test/java/util/UUID/UUIDTest.java

Print this page
rev 9894 : 8006627: UUID to/from String performance should be improved by reducing object allocations

*** 94,103 **** --- 94,120 ---- UUID u1 = UUID.randomUUID(); UUID u2 = UUID.fromString(u1.toString()); if (!u1.equals(u2)) throw new Exception("UUID -> string -> UUID failed"); } + + testFromStringError("-0"); + testFromStringError("x"); + testFromStringError("----"); + testFromStringError("-0-0-0-0"); + testFromStringError("0-0-0-0-"); + testFromStringError("0-0-0-0-0-"); + testFromStringError("0-0-0-0-x"); + } + + private static void testFromStringError(String str) { + try { + UUID test = UUID.fromString(str); + throw new RuntimeException("Should have thrown IAE"); + } catch (IllegalArgumentException iae) { + // pass + } } private static void versionTest() throws Exception { UUID test = UUID.randomUUID(); if (test.version() != 4)