Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ObjectChecker.java 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /*
  2. * Copyright (C) 2008-2010, Google Inc.
  3. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
  4. * and other copyright owners as documented in the project's IP log.
  5. *
  6. * This program and the accompanying materials are made available
  7. * under the terms of the Eclipse Distribution License v1.0 which
  8. * accompanies this distribution, is reproduced below, and is
  9. * available at http://www.eclipse.org/org/documents/edl-v10.php
  10. *
  11. * All rights reserved.
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials provided
  23. * with the distribution.
  24. *
  25. * - Neither the name of the Eclipse Foundation, Inc. nor the
  26. * names of its contributors may be used to endorse or promote
  27. * products derived from this software without specific prior
  28. * written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  31. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  32. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  33. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  39. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  42. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  43. */
  44. package org.eclipse.jgit.lib;
  45. import static org.eclipse.jgit.util.RawParseUtils.match;
  46. import static org.eclipse.jgit.util.RawParseUtils.nextLF;
  47. import static org.eclipse.jgit.util.RawParseUtils.parseBase10;
  48. import java.lang.reflect.InvocationTargetException;
  49. import java.lang.reflect.Method;
  50. import java.text.MessageFormat;
  51. import java.util.HashSet;
  52. import java.util.Locale;
  53. import java.util.Set;
  54. import org.eclipse.jgit.errors.CorruptObjectException;
  55. import org.eclipse.jgit.internal.JGitText;
  56. import org.eclipse.jgit.util.MutableInteger;
  57. import org.eclipse.jgit.util.RawParseUtils;
  58. /**
  59. * Verifies that an object is formatted correctly.
  60. * <p>
  61. * Verifications made by this class only check that the fields of an object are
  62. * formatted correctly. The ObjectId checksum of the object is not verified, and
  63. * connectivity links between objects are also not verified. Its assumed that
  64. * the caller can provide both of these validations on its own.
  65. * <p>
  66. * Instances of this class are not thread safe, but they may be reused to
  67. * perform multiple object validations.
  68. */
  69. public class ObjectChecker {
  70. /** Header "tree " */
  71. public static final byte[] tree = Constants.encodeASCII("tree "); //$NON-NLS-1$
  72. /** Header "parent " */
  73. public static final byte[] parent = Constants.encodeASCII("parent "); //$NON-NLS-1$
  74. /** Header "author " */
  75. public static final byte[] author = Constants.encodeASCII("author "); //$NON-NLS-1$
  76. /** Header "committer " */
  77. public static final byte[] committer = Constants.encodeASCII("committer "); //$NON-NLS-1$
  78. /** Header "encoding " */
  79. public static final byte[] encoding = Constants.encodeASCII("encoding "); //$NON-NLS-1$
  80. /** Header "object " */
  81. public static final byte[] object = Constants.encodeASCII("object "); //$NON-NLS-1$
  82. /** Header "type " */
  83. public static final byte[] type = Constants.encodeASCII("type "); //$NON-NLS-1$
  84. /** Header "tag " */
  85. public static final byte[] tag = Constants.encodeASCII("tag "); //$NON-NLS-1$
  86. /** Header "tagger " */
  87. public static final byte[] tagger = Constants.encodeASCII("tagger "); //$NON-NLS-1$
  88. private final MutableObjectId tempId = new MutableObjectId();
  89. private final MutableInteger ptrout = new MutableInteger();
  90. private boolean allowZeroMode;
  91. private boolean windows;
  92. private boolean macosx;
  93. /**
  94. * Enable accepting leading zero mode in tree entries.
  95. * <p>
  96. * Some broken Git libraries generated leading zeros in the mode part of
  97. * tree entries. This is technically incorrect but gracefully allowed by
  98. * git-core. JGit rejects such trees by default, but may need to accept
  99. * them on broken histories.
  100. *
  101. * @param allow allow leading zero mode.
  102. * @return {@code this}.
  103. * @since 3.4
  104. */
  105. public ObjectChecker setAllowLeadingZeroFileMode(boolean allow) {
  106. allowZeroMode = allow;
  107. return this;
  108. }
  109. /**
  110. * Restrict trees to only names legal on Windows platforms.
  111. * <p>
  112. * Also rejects any mixed case forms of reserved names ({@code .git}).
  113. *
  114. * @param win true if Windows name checking should be performed.
  115. * @return {@code this}.
  116. * @since 3.4
  117. */
  118. public ObjectChecker setSafeForWindows(boolean win) {
  119. windows = win;
  120. return this;
  121. }
  122. /**
  123. * Restrict trees to only names legal on Mac OS X platforms.
  124. * <p>
  125. * Rejects any mixed case forms of reserved names ({@code .git})
  126. * for users working on HFS+ in case-insensitive (default) mode.
  127. *
  128. * @param mac true if Mac OS X name checking should be performed.
  129. * @return {@code this}.
  130. * @since 3.4
  131. */
  132. public ObjectChecker setSafeForMacOS(boolean mac) {
  133. macosx = mac;
  134. return this;
  135. }
  136. /**
  137. * Check an object for parsing errors.
  138. *
  139. * @param objType
  140. * type of the object. Must be a valid object type code in
  141. * {@link Constants}.
  142. * @param raw
  143. * the raw data which comprises the object. This should be in the
  144. * canonical format (that is the format used to generate the
  145. * ObjectId of the object). The array is never modified.
  146. * @throws CorruptObjectException
  147. * if an error is identified.
  148. */
  149. public void check(final int objType, final byte[] raw)
  150. throws CorruptObjectException {
  151. switch (objType) {
  152. case Constants.OBJ_COMMIT:
  153. checkCommit(raw);
  154. break;
  155. case Constants.OBJ_TAG:
  156. checkTag(raw);
  157. break;
  158. case Constants.OBJ_TREE:
  159. checkTree(raw);
  160. break;
  161. case Constants.OBJ_BLOB:
  162. checkBlob(raw);
  163. break;
  164. default:
  165. throw new CorruptObjectException(MessageFormat.format(
  166. JGitText.get().corruptObjectInvalidType2,
  167. Integer.valueOf(objType)));
  168. }
  169. }
  170. private int id(final byte[] raw, final int ptr) {
  171. try {
  172. tempId.fromString(raw, ptr);
  173. return ptr + Constants.OBJECT_ID_STRING_LENGTH;
  174. } catch (IllegalArgumentException e) {
  175. return -1;
  176. }
  177. }
  178. private int personIdent(final byte[] raw, int ptr) {
  179. final int emailB = nextLF(raw, ptr, '<');
  180. if (emailB == ptr || raw[emailB - 1] != '<')
  181. return -1;
  182. final int emailE = nextLF(raw, emailB, '>');
  183. if (emailE == emailB || raw[emailE - 1] != '>')
  184. return -1;
  185. if (emailE == raw.length || raw[emailE] != ' ')
  186. return -1;
  187. parseBase10(raw, emailE + 1, ptrout); // when
  188. ptr = ptrout.value;
  189. if (emailE + 1 == ptr)
  190. return -1;
  191. if (ptr == raw.length || raw[ptr] != ' ')
  192. return -1;
  193. parseBase10(raw, ptr + 1, ptrout); // tz offset
  194. if (ptr + 1 == ptrout.value)
  195. return -1;
  196. return ptrout.value;
  197. }
  198. /**
  199. * Check a commit for errors.
  200. *
  201. * @param raw
  202. * the commit data. The array is never modified.
  203. * @throws CorruptObjectException
  204. * if any error was detected.
  205. */
  206. public void checkCommit(final byte[] raw) throws CorruptObjectException {
  207. int ptr = 0;
  208. if ((ptr = match(raw, ptr, tree)) < 0)
  209. throw new CorruptObjectException("no tree header");
  210. if ((ptr = id(raw, ptr)) < 0 || raw[ptr++] != '\n')
  211. throw new CorruptObjectException("invalid tree");
  212. while (match(raw, ptr, parent) >= 0) {
  213. ptr += parent.length;
  214. if ((ptr = id(raw, ptr)) < 0 || raw[ptr++] != '\n')
  215. throw new CorruptObjectException("invalid parent");
  216. }
  217. if ((ptr = match(raw, ptr, author)) < 0)
  218. throw new CorruptObjectException("no author");
  219. if ((ptr = personIdent(raw, ptr)) < 0 || raw[ptr++] != '\n')
  220. throw new CorruptObjectException("invalid author");
  221. if ((ptr = match(raw, ptr, committer)) < 0)
  222. throw new CorruptObjectException("no committer");
  223. if ((ptr = personIdent(raw, ptr)) < 0 || raw[ptr++] != '\n')
  224. throw new CorruptObjectException("invalid committer");
  225. }
  226. /**
  227. * Check an annotated tag for errors.
  228. *
  229. * @param raw
  230. * the tag data. The array is never modified.
  231. * @throws CorruptObjectException
  232. * if any error was detected.
  233. */
  234. public void checkTag(final byte[] raw) throws CorruptObjectException {
  235. int ptr = 0;
  236. if ((ptr = match(raw, ptr, object)) < 0)
  237. throw new CorruptObjectException("no object header");
  238. if ((ptr = id(raw, ptr)) < 0 || raw[ptr++] != '\n')
  239. throw new CorruptObjectException("invalid object");
  240. if ((ptr = match(raw, ptr, type)) < 0)
  241. throw new CorruptObjectException("no type header");
  242. ptr = nextLF(raw, ptr);
  243. if ((ptr = match(raw, ptr, tag)) < 0)
  244. throw new CorruptObjectException("no tag header");
  245. ptr = nextLF(raw, ptr);
  246. if ((ptr = match(raw, ptr, tagger)) > 0) {
  247. if ((ptr = personIdent(raw, ptr)) < 0 || raw[ptr++] != '\n')
  248. throw new CorruptObjectException("invalid tagger");
  249. }
  250. }
  251. private static int lastPathChar(final int mode) {
  252. return FileMode.TREE.equals(mode) ? '/' : '\0';
  253. }
  254. private static int pathCompare(final byte[] raw, int aPos, final int aEnd,
  255. final int aMode, int bPos, final int bEnd, final int bMode) {
  256. while (aPos < aEnd && bPos < bEnd) {
  257. final int cmp = (raw[aPos++] & 0xff) - (raw[bPos++] & 0xff);
  258. if (cmp != 0)
  259. return cmp;
  260. }
  261. if (aPos < aEnd)
  262. return (raw[aPos] & 0xff) - lastPathChar(bMode);
  263. if (bPos < bEnd)
  264. return lastPathChar(aMode) - (raw[bPos] & 0xff);
  265. return 0;
  266. }
  267. private static boolean duplicateName(final byte[] raw,
  268. final int thisNamePos, final int thisNameEnd) {
  269. final int sz = raw.length;
  270. int nextPtr = thisNameEnd + 1 + Constants.OBJECT_ID_LENGTH;
  271. for (;;) {
  272. int nextMode = 0;
  273. for (;;) {
  274. if (nextPtr >= sz)
  275. return false;
  276. final byte c = raw[nextPtr++];
  277. if (' ' == c)
  278. break;
  279. nextMode <<= 3;
  280. nextMode += c - '0';
  281. }
  282. final int nextNamePos = nextPtr;
  283. for (;;) {
  284. if (nextPtr == sz)
  285. return false;
  286. final byte c = raw[nextPtr++];
  287. if (c == 0)
  288. break;
  289. }
  290. if (nextNamePos + 1 == nextPtr)
  291. return false;
  292. final int cmp = pathCompare(raw, thisNamePos, thisNameEnd,
  293. FileMode.TREE.getBits(), nextNamePos, nextPtr - 1, nextMode);
  294. if (cmp < 0)
  295. return false;
  296. else if (cmp == 0)
  297. return true;
  298. nextPtr += Constants.OBJECT_ID_LENGTH;
  299. }
  300. }
  301. /**
  302. * Check a canonical formatted tree for errors.
  303. *
  304. * @param raw
  305. * the raw tree data. The array is never modified.
  306. * @throws CorruptObjectException
  307. * if any error was detected.
  308. */
  309. public void checkTree(final byte[] raw) throws CorruptObjectException {
  310. final int sz = raw.length;
  311. int ptr = 0;
  312. int lastNameB = 0, lastNameE = 0, lastMode = 0;
  313. Set<String> normalized = windows || macosx
  314. ? new HashSet<String>()
  315. : null;
  316. while (ptr < sz) {
  317. int thisMode = 0;
  318. for (;;) {
  319. if (ptr == sz)
  320. throw new CorruptObjectException("truncated in mode");
  321. final byte c = raw[ptr++];
  322. if (' ' == c)
  323. break;
  324. if (c < '0' || c > '7')
  325. throw new CorruptObjectException("invalid mode character");
  326. if (thisMode == 0 && c == '0' && !allowZeroMode)
  327. throw new CorruptObjectException("mode starts with '0'");
  328. thisMode <<= 3;
  329. thisMode += c - '0';
  330. }
  331. if (FileMode.fromBits(thisMode).getObjectType() == Constants.OBJ_BAD)
  332. throw new CorruptObjectException("invalid mode " + thisMode);
  333. final int thisNameB = ptr;
  334. ptr = scanPathSegment(raw, ptr, sz);
  335. if (ptr == sz || raw[ptr] != 0)
  336. throw new CorruptObjectException("truncated in name");
  337. checkPathSegment2(raw, thisNameB, ptr);
  338. if (normalized != null) {
  339. if (!normalized.add(normalize(raw, thisNameB, ptr)))
  340. throw new CorruptObjectException("duplicate entry names");
  341. } else if (duplicateName(raw, thisNameB, ptr))
  342. throw new CorruptObjectException("duplicate entry names");
  343. if (lastNameB != 0) {
  344. final int cmp = pathCompare(raw, lastNameB, lastNameE,
  345. lastMode, thisNameB, ptr, thisMode);
  346. if (cmp > 0)
  347. throw new CorruptObjectException("incorrectly sorted");
  348. }
  349. lastNameB = thisNameB;
  350. lastNameE = ptr;
  351. lastMode = thisMode;
  352. ptr += 1 + Constants.OBJECT_ID_LENGTH;
  353. if (ptr > sz)
  354. throw new CorruptObjectException("truncated in object id");
  355. }
  356. }
  357. private int scanPathSegment(byte[] raw, int ptr, int end)
  358. throws CorruptObjectException {
  359. for (; ptr < end; ptr++) {
  360. byte c = raw[ptr];
  361. if (c == 0)
  362. return ptr;
  363. if (c == '/')
  364. throw new CorruptObjectException("name contains '/'");
  365. if (windows && isInvalidOnWindows(c)) {
  366. if (c > 31)
  367. throw new CorruptObjectException(String.format(
  368. "name contains '%c'", c));
  369. throw new CorruptObjectException(String.format(
  370. "name contains byte 0x%x", c & 0xff));
  371. }
  372. }
  373. return ptr;
  374. }
  375. /**
  376. * Check tree path entry for validity.
  377. *
  378. * @param raw buffer to scan.
  379. * @param ptr offset to first byte of the name.
  380. * @param end offset to one past last byte of name.
  381. * @throws CorruptObjectException name is invalid.
  382. * @since 3.4
  383. */
  384. public void checkPathSegment(byte[] raw, int ptr, int end)
  385. throws CorruptObjectException {
  386. int e = scanPathSegment(raw, ptr, end);
  387. if (e < end && raw[e] == 0)
  388. throw new CorruptObjectException("name contains byte 0x00");
  389. checkPathSegment2(raw, ptr, end);
  390. }
  391. private void checkPathSegment2(byte[] raw, int ptr, int end)
  392. throws CorruptObjectException {
  393. if (ptr == end)
  394. throw new CorruptObjectException("zero length name");
  395. if (raw[ptr] == '.') {
  396. switch (end - ptr) {
  397. case 1:
  398. throw new CorruptObjectException("invalid name '.'");
  399. case 2:
  400. if (raw[ptr + 1] == '.')
  401. throw new CorruptObjectException("invalid name '..'");
  402. break;
  403. case 4:
  404. if (isDotGit(raw, ptr + 1))
  405. throw new CorruptObjectException(String.format(
  406. "invalid name '%s'",
  407. RawParseUtils.decode(raw, ptr, end)));
  408. }
  409. }
  410. if (windows) {
  411. // Windows ignores space and dot at end of file name.
  412. if (raw[end - 1] == ' ' || raw[end - 1] == '.')
  413. throw new CorruptObjectException("invalid name ends with '"
  414. + ((char) raw[end - 1]) + "'");
  415. if (end - ptr >= 3)
  416. checkNotWindowsDevice(raw, ptr, end);
  417. }
  418. }
  419. private static void checkNotWindowsDevice(byte[] raw, int ptr, int end)
  420. throws CorruptObjectException {
  421. switch (toLower(raw[ptr])) {
  422. case 'a': // AUX
  423. if (end - ptr >= 3
  424. && toLower(raw[ptr + 1]) == 'u'
  425. && toLower(raw[ptr + 2]) == 'x'
  426. && (end - ptr == 3 || raw[ptr + 3] == '.'))
  427. throw new CorruptObjectException("invalid name 'AUX'");
  428. break;
  429. case 'c': // CON, COM[1-9]
  430. if (end - ptr >= 3
  431. && toLower(raw[ptr + 2]) == 'n'
  432. && toLower(raw[ptr + 1]) == 'o'
  433. && (end - ptr == 3 || raw[ptr + 3] == '.'))
  434. throw new CorruptObjectException("invalid name 'CON'");
  435. if (end - ptr >= 4
  436. && toLower(raw[ptr + 2]) == 'm'
  437. && toLower(raw[ptr + 1]) == 'o'
  438. && isPositiveDigit(raw[ptr + 3])
  439. && (end - ptr == 4 || raw[ptr + 4] == '.'))
  440. throw new CorruptObjectException("invalid name 'COM"
  441. + ((char) raw[ptr + 3]) + "'");
  442. break;
  443. case 'l': // LPT[1-9]
  444. if (end - ptr >= 4
  445. && toLower(raw[ptr + 1]) == 'p'
  446. && toLower(raw[ptr + 2]) == 't'
  447. && isPositiveDigit(raw[ptr + 3])
  448. && (end - ptr == 4 || raw[ptr + 4] == '.'))
  449. throw new CorruptObjectException("invalid name 'LPT"
  450. + ((char) raw[ptr + 3]) + "'");
  451. break;
  452. case 'n': // NUL
  453. if (end - ptr >= 3
  454. && toLower(raw[ptr + 1]) == 'u'
  455. && toLower(raw[ptr + 2]) == 'l'
  456. && (end - ptr == 3 || raw[ptr + 3] == '.'))
  457. throw new CorruptObjectException("invalid name 'NUL'");
  458. break;
  459. case 'p': // PRN
  460. if (end - ptr >= 3
  461. && toLower(raw[ptr + 1]) == 'r'
  462. && toLower(raw[ptr + 2]) == 'n'
  463. && (end - ptr == 3 || raw[ptr + 3] == '.'))
  464. throw new CorruptObjectException("invalid name 'PRN'");
  465. break;
  466. }
  467. }
  468. private static boolean isInvalidOnWindows(byte c) {
  469. // Windows disallows "special" characters in a path component.
  470. switch (c) {
  471. case '"':
  472. case '*':
  473. case ':':
  474. case '<':
  475. case '>':
  476. case '?':
  477. case '\\':
  478. case '|':
  479. return true;
  480. }
  481. return 1 <= c && c <= 31;
  482. }
  483. private static boolean isDotGit(byte[] buf, int p) {
  484. return toLower(buf[p]) == 'g'
  485. && toLower(buf[p + 1]) == 'i'
  486. && toLower(buf[p + 2]) == 't';
  487. }
  488. private static char toLower(byte b) {
  489. if ('A' <= b && b <= 'Z')
  490. return (char) (b + ('a' - 'A'));
  491. return (char) b;
  492. }
  493. private static boolean isPositiveDigit(byte b) {
  494. return '1' <= b && b <= '9';
  495. }
  496. /**
  497. * Check a blob for errors.
  498. *
  499. * @param raw
  500. * the blob data. The array is never modified.
  501. * @throws CorruptObjectException
  502. * if any error was detected.
  503. */
  504. public void checkBlob(final byte[] raw) throws CorruptObjectException {
  505. // We can always assume the blob is valid.
  506. }
  507. private String normalize(byte[] raw, int ptr, int end) {
  508. String n = RawParseUtils.decode(raw, ptr, end).toLowerCase(Locale.US);
  509. return macosx ? Normalizer.normalize(n) : n;
  510. }
  511. private static class Normalizer {
  512. // TODO Simplify invocation to Normalizer after dropping Java 5.
  513. private static final Method normalize;
  514. private static final Object nfc;
  515. static {
  516. Method method;
  517. Object formNfc;
  518. try {
  519. Class<?> formClazz = Class.forName("java.text.Normalizer$Form"); //$NON-NLS-1$
  520. formNfc = formClazz.getField("NFC").get(null); //$NON-NLS-1$
  521. method = Class.forName("java.text.Normalizer") //$NON-NLS-1$
  522. .getMethod("normalize", CharSequence.class, formClazz); //$NON-NLS-1$
  523. } catch (ClassNotFoundException e) {
  524. method = null;
  525. formNfc = null;
  526. } catch (NoSuchFieldException e) {
  527. method = null;
  528. formNfc = null;
  529. } catch (NoSuchMethodException e) {
  530. method = null;
  531. formNfc = null;
  532. } catch (SecurityException e) {
  533. method = null;
  534. formNfc = null;
  535. } catch (IllegalArgumentException e) {
  536. method = null;
  537. formNfc = null;
  538. } catch (IllegalAccessException e) {
  539. method = null;
  540. formNfc = null;
  541. }
  542. normalize = method;
  543. nfc = formNfc;
  544. }
  545. static String normalize(String in) {
  546. if (normalize == null)
  547. return in;
  548. try {
  549. return (String) normalize.invoke(null, in, nfc);
  550. } catch (IllegalAccessException e) {
  551. return in;
  552. } catch (InvocationTargetException e) {
  553. if (e.getCause() instanceof RuntimeException)
  554. throw (RuntimeException) e.getCause();
  555. if (e.getCause() instanceof Error)
  556. throw (Error) e.getCause();
  557. return in;
  558. }
  559. }
  560. }
  561. }