JDK-8188902 : UUID.fromString does not work as expected
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 8u144
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86_64
  • Submitted: 2017-10-02
  • Updated: 2019-01-09
  • Resolved: 2017-10-09
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux nuberdev23.corporate.local 3.10.0-327.28.3.el7.x86_64 #1 SMP Fri Aug 12 13:21:05 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
UUID.fromString(UUID.fromString("48b19be3-1f35-49a8-bc63-1ebd8ef5f93eaaa")).toString() is not 48b19be3-1f35-49a8-bc63-1ebd8ef5f93eaaa.  No IllegalArgumentException is thrown.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the following in jjs
UUID=java.util.UUID;
UUID.fromString(UUID.fromString("48b19be3-1f35-49a8-bc63-1ebd8ef5f93eaaa")).toString()

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect that an IllegalArgumentException is thrown based on the specification and javadoc.  

Based on http://bugs.java.com/view_bug.do?bug_id=8159339 I would expect that this be documented in the javadoc as UUID.fromString requires validating of user input.
ACTUAL -
the result in JJS was not in the input value to the UUID library.

the test case failed

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
  @Test(expected = IllegalArgumentException.class)
  public void testUUIDfromString() {
    String uuidString = "48b19be3-1f35-49a8-bc63-1ebd8ef5f93eaaa";
    UUID uuid = UUID.fromString(uuidString);
    System.err.println(System.getProperty("java.version"));
    assertEquals("The input to fromString and the output of toString should be identical", uuidString, uuid.toString());
    fail("fromString did not throw an exception and incorrectly created a larger than expected UUID");
  }
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
UUID uuid = UUID.fromString(uuidString);
if(!uuid.toString().equals(uuidString)) {
    throw new IllegalArgumentException();
}


Comments
This behaves correctly in JDK 9. Following is the output with the test case on JDK 9+181: D:\Java7Workspace\TestCases\src>java JI9051057 Exception in thread "main" java.lang.IllegalArgumentException: UUID string too large at java.base/java.util.UUID.fromString(UUID.java:199) at JI9051057.main(JI9051057.java:11)
09-10-2017