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 ----------
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 ----------
- duplicates
-
JDK-8159339 UUID:fromString() parses incorrect strings without error
- Closed
- relates to
-
JDK-8216407 java.util.UUID.fromString accepts input that does not match expected format
- Open