You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UnpackedObjectTest.java 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. /*
  2. * Copyright (C) 2010, Google Inc.
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.internal.storage.file;
  44. import static org.junit.Assert.assertEquals;
  45. import static org.junit.Assert.assertFalse;
  46. import static org.junit.Assert.assertNotNull;
  47. import static org.junit.Assert.assertTrue;
  48. import static org.junit.Assert.fail;
  49. import java.io.ByteArrayInputStream;
  50. import java.io.ByteArrayOutputStream;
  51. import java.io.File;
  52. import java.io.FileInputStream;
  53. import java.io.FileOutputStream;
  54. import java.io.IOException;
  55. import java.io.InputStream;
  56. import java.text.MessageFormat;
  57. import java.util.Arrays;
  58. import java.util.zip.DeflaterOutputStream;
  59. import org.eclipse.jgit.errors.CorruptObjectException;
  60. import org.eclipse.jgit.errors.LargeObjectException;
  61. import org.eclipse.jgit.internal.JGitText;
  62. import org.eclipse.jgit.junit.JGitTestUtil;
  63. import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
  64. import org.eclipse.jgit.junit.TestRng;
  65. import org.eclipse.jgit.lib.Constants;
  66. import org.eclipse.jgit.lib.ObjectId;
  67. import org.eclipse.jgit.lib.ObjectInserter;
  68. import org.eclipse.jgit.lib.ObjectLoader;
  69. import org.eclipse.jgit.lib.ObjectStream;
  70. import org.eclipse.jgit.storage.file.WindowCacheConfig;
  71. import org.eclipse.jgit.util.FileUtils;
  72. import org.eclipse.jgit.util.IO;
  73. import org.junit.After;
  74. import org.junit.Before;
  75. import org.junit.Test;
  76. public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
  77. private int streamThreshold = 16 * 1024;
  78. private TestRng rng;
  79. private FileRepository repo;
  80. private WindowCursor wc;
  81. private TestRng getRng() {
  82. if (rng == null)
  83. rng = new TestRng(JGitTestUtil.getName());
  84. return rng;
  85. }
  86. @Override
  87. @Before
  88. public void setUp() throws Exception {
  89. super.setUp();
  90. WindowCacheConfig cfg = new WindowCacheConfig();
  91. cfg.setStreamFileThreshold(streamThreshold);
  92. cfg.install();
  93. repo = createBareRepository();
  94. wc = (WindowCursor) repo.newObjectReader();
  95. }
  96. @Override
  97. @After
  98. public void tearDown() throws Exception {
  99. if (wc != null)
  100. wc.close();
  101. new WindowCacheConfig().install();
  102. super.tearDown();
  103. }
  104. @Test
  105. public void testStandardFormat_SmallObject() throws Exception {
  106. final int type = Constants.OBJ_BLOB;
  107. byte[] data = getRng().nextBytes(300);
  108. byte[] gz = compressStandardFormat(type, data);
  109. ObjectId id = ObjectId.zeroId();
  110. ObjectLoader ol = UnpackedObject.open(new ByteArrayInputStream(gz),
  111. path(id), id, wc);
  112. assertNotNull("created loader", ol);
  113. assertEquals(type, ol.getType());
  114. assertEquals(data.length, ol.getSize());
  115. assertFalse("is not large", ol.isLarge());
  116. assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
  117. try (ObjectStream in = ol.openStream()) {
  118. assertNotNull("have stream", in);
  119. assertEquals(type, in.getType());
  120. assertEquals(data.length, in.getSize());
  121. byte[] data2 = new byte[data.length];
  122. IO.readFully(in, data2, 0, data.length);
  123. assertTrue("same content", Arrays.equals(data2, data));
  124. assertEquals("stream at EOF", -1, in.read());
  125. }
  126. }
  127. @Test
  128. public void testStandardFormat_LargeObject() throws Exception {
  129. final int type = Constants.OBJ_BLOB;
  130. byte[] data = getRng().nextBytes(streamThreshold + 5);
  131. ObjectId id = getId(type, data);
  132. write(id, compressStandardFormat(type, data));
  133. ObjectLoader ol;
  134. {
  135. try (FileInputStream fs = new FileInputStream(path(id))) {
  136. ol = UnpackedObject.open(fs, path(id), id, wc);
  137. }
  138. }
  139. assertNotNull("created loader", ol);
  140. assertEquals(type, ol.getType());
  141. assertEquals(data.length, ol.getSize());
  142. assertTrue("is large", ol.isLarge());
  143. try {
  144. ol.getCachedBytes();
  145. fail("Should have thrown LargeObjectException");
  146. } catch (LargeObjectException tooBig) {
  147. assertEquals(MessageFormat.format(
  148. JGitText.get().largeObjectException, id.name()), tooBig
  149. .getMessage());
  150. }
  151. try (ObjectStream in = ol.openStream()) {
  152. assertNotNull("have stream", in);
  153. assertEquals(type, in.getType());
  154. assertEquals(data.length, in.getSize());
  155. byte[] data2 = new byte[data.length];
  156. IO.readFully(in, data2, 0, data.length);
  157. assertTrue("same content", Arrays.equals(data2, data));
  158. assertEquals("stream at EOF", -1, in.read());
  159. }
  160. }
  161. @Test
  162. public void testStandardFormat_NegativeSize() throws Exception {
  163. ObjectId id = ObjectId.zeroId();
  164. byte[] data = getRng().nextBytes(300);
  165. try {
  166. byte[] gz = compressStandardFormat("blob", "-1", data);
  167. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  168. fail("Did not throw CorruptObjectException");
  169. } catch (CorruptObjectException coe) {
  170. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  171. id.name(), JGitText.get().corruptObjectNegativeSize), coe
  172. .getMessage());
  173. }
  174. }
  175. @Test
  176. public void testStandardFormat_InvalidType() throws Exception {
  177. ObjectId id = ObjectId.zeroId();
  178. byte[] data = getRng().nextBytes(300);
  179. try {
  180. byte[] gz = compressStandardFormat("not.a.type", "1", data);
  181. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  182. fail("Did not throw CorruptObjectException");
  183. } catch (CorruptObjectException coe) {
  184. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  185. id.name(), JGitText.get().corruptObjectInvalidType), coe
  186. .getMessage());
  187. }
  188. }
  189. @Test
  190. public void testStandardFormat_NoHeader() throws Exception {
  191. ObjectId id = ObjectId.zeroId();
  192. byte[] data = {};
  193. try {
  194. byte[] gz = compressStandardFormat("", "", data);
  195. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  196. fail("Did not throw CorruptObjectException");
  197. } catch (CorruptObjectException coe) {
  198. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  199. id.name(), JGitText.get().corruptObjectNoHeader), coe
  200. .getMessage());
  201. }
  202. }
  203. @Test
  204. public void testStandardFormat_GarbageAfterSize() throws Exception {
  205. ObjectId id = ObjectId.zeroId();
  206. byte[] data = getRng().nextBytes(300);
  207. try {
  208. byte[] gz = compressStandardFormat("blob", "1foo", data);
  209. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  210. fail("Did not throw CorruptObjectException");
  211. } catch (CorruptObjectException coe) {
  212. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  213. id.name(), JGitText.get().corruptObjectGarbageAfterSize),
  214. coe.getMessage());
  215. }
  216. }
  217. @Test
  218. public void testStandardFormat_SmallObject_CorruptZLibStream()
  219. throws Exception {
  220. ObjectId id = ObjectId.zeroId();
  221. byte[] data = getRng().nextBytes(300);
  222. try {
  223. byte[] gz = compressStandardFormat(Constants.OBJ_BLOB, data);
  224. for (int i = 5; i < gz.length; i++)
  225. gz[i] = 0;
  226. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  227. fail("Did not throw CorruptObjectException");
  228. } catch (CorruptObjectException coe) {
  229. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  230. id.name(), JGitText.get().corruptObjectBadStream), coe
  231. .getMessage());
  232. }
  233. }
  234. @Test
  235. public void testStandardFormat_SmallObject_TruncatedZLibStream()
  236. throws Exception {
  237. ObjectId id = ObjectId.zeroId();
  238. byte[] data = getRng().nextBytes(300);
  239. try {
  240. byte[] gz = compressStandardFormat(Constants.OBJ_BLOB, data);
  241. byte[] tr = new byte[gz.length - 1];
  242. System.arraycopy(gz, 0, tr, 0, tr.length);
  243. UnpackedObject.open(new ByteArrayInputStream(tr), path(id), id, wc);
  244. fail("Did not throw CorruptObjectException");
  245. } catch (CorruptObjectException coe) {
  246. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  247. id.name(), JGitText.get().corruptObjectBadStream), coe
  248. .getMessage());
  249. }
  250. }
  251. @Test
  252. public void testStandardFormat_SmallObject_TrailingGarbage()
  253. throws Exception {
  254. ObjectId id = ObjectId.zeroId();
  255. byte[] data = getRng().nextBytes(300);
  256. try {
  257. byte[] gz = compressStandardFormat(Constants.OBJ_BLOB, data);
  258. byte[] tr = new byte[gz.length + 1];
  259. System.arraycopy(gz, 0, tr, 0, gz.length);
  260. UnpackedObject.open(new ByteArrayInputStream(tr), path(id), id, wc);
  261. fail("Did not throw CorruptObjectException");
  262. } catch (CorruptObjectException coe) {
  263. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  264. id.name(), JGitText.get().corruptObjectBadStream), coe
  265. .getMessage());
  266. }
  267. }
  268. @Test
  269. public void testStandardFormat_LargeObject_CorruptZLibStream()
  270. throws Exception {
  271. final int type = Constants.OBJ_BLOB;
  272. byte[] data = getRng().nextBytes(streamThreshold + 5);
  273. ObjectId id = getId(type, data);
  274. byte[] gz = compressStandardFormat(type, data);
  275. gz[gz.length - 1] = 0;
  276. gz[gz.length - 2] = 0;
  277. write(id, gz);
  278. ObjectLoader ol;
  279. try (FileInputStream fs = new FileInputStream(path(id))) {
  280. ol = UnpackedObject.open(fs, path(id), id, wc);
  281. }
  282. byte[] tmp = new byte[data.length];
  283. try (InputStream in = ol.openStream()) {
  284. IO.readFully(in, tmp, 0, tmp.length);
  285. fail("Did not throw CorruptObjectException");
  286. } catch (CorruptObjectException coe) {
  287. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  288. id.name(), JGitText.get().corruptObjectBadStream), coe
  289. .getMessage());
  290. }
  291. }
  292. @Test
  293. public void testStandardFormat_LargeObject_TruncatedZLibStream()
  294. throws Exception {
  295. final int type = Constants.OBJ_BLOB;
  296. byte[] data = getRng().nextBytes(streamThreshold + 5);
  297. ObjectId id = getId(type, data);
  298. byte[] gz = compressStandardFormat(type, data);
  299. byte[] tr = new byte[gz.length - 1];
  300. System.arraycopy(gz, 0, tr, 0, tr.length);
  301. write(id, tr);
  302. ObjectLoader ol;
  303. try (FileInputStream fs = new FileInputStream(path(id))) {
  304. ol = UnpackedObject.open(fs, path(id), id, wc);
  305. }
  306. byte[] tmp = new byte[data.length];
  307. @SuppressWarnings("resource") // We are testing that the close() method throws
  308. InputStream in = ol.openStream();
  309. IO.readFully(in, tmp, 0, tmp.length);
  310. try {
  311. in.close();
  312. fail("close did not throw CorruptObjectException");
  313. } catch (CorruptObjectException coe) {
  314. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  315. id.name(), JGitText.get().corruptObjectBadStream), coe
  316. .getMessage());
  317. }
  318. }
  319. @Test
  320. public void testStandardFormat_LargeObject_TrailingGarbage()
  321. throws Exception {
  322. final int type = Constants.OBJ_BLOB;
  323. byte[] data = getRng().nextBytes(streamThreshold + 5);
  324. ObjectId id = getId(type, data);
  325. byte[] gz = compressStandardFormat(type, data);
  326. byte[] tr = new byte[gz.length + 1];
  327. System.arraycopy(gz, 0, tr, 0, gz.length);
  328. write(id, tr);
  329. ObjectLoader ol;
  330. try (FileInputStream fs = new FileInputStream(path(id))) {
  331. ol = UnpackedObject.open(fs, path(id), id, wc);
  332. }
  333. byte[] tmp = new byte[data.length];
  334. @SuppressWarnings("resource") // We are testing that the close() method throws
  335. InputStream in = ol.openStream();
  336. IO.readFully(in, tmp, 0, tmp.length);
  337. try {
  338. in.close();
  339. fail("close did not throw CorruptObjectException");
  340. } catch (CorruptObjectException coe) {
  341. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  342. id.name(), JGitText.get().corruptObjectBadStream), coe
  343. .getMessage());
  344. }
  345. }
  346. @Test
  347. public void testPackFormat_SmallObject() throws Exception {
  348. final int type = Constants.OBJ_BLOB;
  349. byte[] data = getRng().nextBytes(300);
  350. byte[] gz = compressPackFormat(type, data);
  351. ObjectId id = ObjectId.zeroId();
  352. ObjectLoader ol = UnpackedObject.open(new ByteArrayInputStream(gz),
  353. path(id), id, wc);
  354. assertNotNull("created loader", ol);
  355. assertEquals(type, ol.getType());
  356. assertEquals(data.length, ol.getSize());
  357. assertFalse("is not large", ol.isLarge());
  358. assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
  359. try (ObjectStream in = ol.openStream()) {
  360. assertNotNull("have stream", in);
  361. assertEquals(type, in.getType());
  362. assertEquals(data.length, in.getSize());
  363. byte[] data2 = new byte[data.length];
  364. IO.readFully(in, data2, 0, data.length);
  365. assertTrue("same content",
  366. Arrays.equals(data, ol.getCachedBytes()));
  367. }
  368. }
  369. @Test
  370. public void testPackFormat_LargeObject() throws Exception {
  371. final int type = Constants.OBJ_BLOB;
  372. byte[] data = getRng().nextBytes(streamThreshold + 5);
  373. ObjectId id = getId(type, data);
  374. write(id, compressPackFormat(type, data));
  375. ObjectLoader ol;
  376. try (FileInputStream fs = new FileInputStream(path(id))) {
  377. ol = UnpackedObject.open(fs, path(id), id, wc);
  378. }
  379. assertNotNull("created loader", ol);
  380. assertEquals(type, ol.getType());
  381. assertEquals(data.length, ol.getSize());
  382. assertTrue("is large", ol.isLarge());
  383. try {
  384. ol.getCachedBytes();
  385. fail("Should have thrown LargeObjectException");
  386. } catch (LargeObjectException tooBig) {
  387. assertEquals(MessageFormat.format(
  388. JGitText.get().largeObjectException, id.name()), tooBig
  389. .getMessage());
  390. }
  391. try (ObjectStream in = ol.openStream()) {
  392. assertNotNull("have stream", in);
  393. assertEquals(type, in.getType());
  394. assertEquals(data.length, in.getSize());
  395. byte[] data2 = new byte[data.length];
  396. IO.readFully(in, data2, 0, data.length);
  397. assertTrue("same content", Arrays.equals(data2, data));
  398. assertEquals("stream at EOF", -1, in.read());
  399. }
  400. }
  401. @Test
  402. public void testPackFormat_DeltaNotAllowed() throws Exception {
  403. ObjectId id = ObjectId.zeroId();
  404. byte[] data = getRng().nextBytes(300);
  405. try {
  406. byte[] gz = compressPackFormat(Constants.OBJ_OFS_DELTA, data);
  407. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  408. fail("Did not throw CorruptObjectException");
  409. } catch (CorruptObjectException coe) {
  410. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  411. id.name(), JGitText.get().corruptObjectInvalidType), coe
  412. .getMessage());
  413. }
  414. try {
  415. byte[] gz = compressPackFormat(Constants.OBJ_REF_DELTA, data);
  416. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  417. fail("Did not throw CorruptObjectException");
  418. } catch (CorruptObjectException coe) {
  419. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  420. id.name(), JGitText.get().corruptObjectInvalidType), coe
  421. .getMessage());
  422. }
  423. try {
  424. byte[] gz = compressPackFormat(Constants.OBJ_TYPE_5, data);
  425. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  426. fail("Did not throw CorruptObjectException");
  427. } catch (CorruptObjectException coe) {
  428. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  429. id.name(), JGitText.get().corruptObjectInvalidType), coe
  430. .getMessage());
  431. }
  432. try {
  433. byte[] gz = compressPackFormat(Constants.OBJ_EXT, data);
  434. UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
  435. fail("Did not throw CorruptObjectException");
  436. } catch (CorruptObjectException coe) {
  437. assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
  438. id.name(), JGitText.get().corruptObjectInvalidType), coe
  439. .getMessage());
  440. }
  441. }
  442. private static byte[] compressStandardFormat(int type, byte[] data)
  443. throws IOException {
  444. String typeString = Constants.typeString(type);
  445. String length = String.valueOf(data.length);
  446. return compressStandardFormat(typeString, length, data);
  447. }
  448. private static byte[] compressStandardFormat(String type, String length,
  449. byte[] data) throws IOException {
  450. ByteArrayOutputStream out = new ByteArrayOutputStream();
  451. DeflaterOutputStream d = new DeflaterOutputStream(out);
  452. d.write(Constants.encodeASCII(type));
  453. d.write(' ');
  454. d.write(Constants.encodeASCII(length));
  455. d.write(0);
  456. d.write(data);
  457. d.finish();
  458. return out.toByteArray();
  459. }
  460. private static byte[] compressPackFormat(int type, byte[] data)
  461. throws IOException {
  462. byte[] hdr = new byte[64];
  463. int rawLength = data.length;
  464. int nextLength = rawLength >>> 4;
  465. hdr[0] = (byte) ((nextLength > 0 ? 0x80 : 0x00) | (type << 4) | (rawLength & 0x0F));
  466. rawLength = nextLength;
  467. int n = 1;
  468. while (rawLength > 0) {
  469. nextLength >>>= 7;
  470. hdr[n++] = (byte) ((nextLength > 0 ? 0x80 : 0x00) | (rawLength & 0x7F));
  471. rawLength = nextLength;
  472. }
  473. final ByteArrayOutputStream out = new ByteArrayOutputStream();
  474. out.write(hdr, 0, n);
  475. DeflaterOutputStream d = new DeflaterOutputStream(out);
  476. d.write(data);
  477. d.finish();
  478. return out.toByteArray();
  479. }
  480. private File path(ObjectId id) {
  481. return repo.getObjectDatabase().fileFor(id);
  482. }
  483. private void write(ObjectId id, byte[] data) throws IOException {
  484. File path = path(id);
  485. FileUtils.mkdirs(path.getParentFile());
  486. try (FileOutputStream out = new FileOutputStream(path)) {
  487. out.write(data);
  488. }
  489. }
  490. private ObjectId getId(int type, byte[] data) {
  491. try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
  492. return formatter.idFor(type, data);
  493. }
  494. }
  495. }