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

UUID.fromString accepts invalid UUIDs or throws wrong exception

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      The documentation of java.util.UUID.fromString states that it throws an IllegalArgumentException if the UUID string passed to it is invalid, yet it accepts blatantly invalid strings and returns weird UUID objects, or it throws the wrong type of exception. The implementation of the method is abysmally poor.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.UUID;

      public class UUIDBug {
          public static void main(String... args) {
              // should throw, but instead returns 00000000-0000-0000-0000-000000000000
              System.out.println(UUID.fromString("000000000000000000000000-000000000000000000000000-000000000000000000000000-000000000000000000000000-000000000000000000000000"));
              
              // should throw, but instead returns 33337777-7777-4444-5555-222233334444
              System.out.println(UUID.fromString("1111222233334444-1111222233334444-1111222233334444-1111222233334444-1111222233334444"));
              
              // should throw, but instead returns 0defadef-adef-aced-aced-00000defaced
              System.out.println(UUID.fromString("defaced-defaced-defaced-defaced-defaced"));
              
              // should throw, but instead returns 0000000e-000f-000f-000e-00000000000d
              System.out.println(UUID.fromString("e-f-f-e-d"));
              
              // throws wrong type of exception (NumberFormatException instead of IllegalArgumentException)
              System.out.println(UUID.fromString("This-is-not-a-UUID"));
          }
      }
      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              rpatil Ramanand Patil (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: