Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8188902

UUID.fromString does not work as expected

    XMLWordPrintable

Details

    • x86_64
    • linux

    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();
      }

      Attachments

        Issue Links

          Activity

            People

              psonal Pallavi Sonal (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: