ADDITIONAL SYSTEM INFORMATION :
Mac OS X 10.13.6, Java 10.0.1, as well as 1.8
A DESCRIPTION OF THE PROBLEM :
The UUID.fromString javadoc states that the input is parsed according to the format specified in UUID.toString, and will throw IllegalArgumentException if the input does not conform to that format. However, the fromString method accepts a more liberal set of input values than is described in the toString BNF.
Either the javadoc is misleading about what is allowed, or the implementation is incorrect in what it accepts.
Example (jshell 10.0.1):
jshell> UUID.fromString("1-1-1-1-1")
$2 ==> 00000001-0001-0001-0001-000000000001
Yet the input format does not match what is described in the toString doc.
Also, here is another example where the input is accepted perversely:
jshell> UUID.fromString("5-4-3-DEADBEEF0002-9000000001")
$3 ==> 00000005-0004-0003-0002-009000000001
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
UUID.fromString("5-4-3-DEADBEEF0002-9000000001")
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
an IllegalArgumentException should be thrown
ACTUAL -
UUID object '00000005-0004-0003-0002-009000000001' is returned
---------- BEGIN SOURCE ----------
import java.util.UUID;
class Test{
public static void main(String[] args) throws Exception{
String input="5-4-3-DEADBEEF0002-9000000001";
System.out.println("Calling UUID.fromString with input: "+input);
try{
UUID uuid=UUID.fromString(input);
throw new Exception("Expected IllegalArgumentException exception but got: "+uuid );
}catch(IllegalArgumentException e){
System.out.println("OK: caught exception: "+e);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The only workaround is to manually validate UUID format before calling UUID.fromString
Mac OS X 10.13.6, Java 10.0.1, as well as 1.8
A DESCRIPTION OF THE PROBLEM :
The UUID.fromString javadoc states that the input is parsed according to the format specified in UUID.toString, and will throw IllegalArgumentException if the input does not conform to that format. However, the fromString method accepts a more liberal set of input values than is described in the toString BNF.
Either the javadoc is misleading about what is allowed, or the implementation is incorrect in what it accepts.
Example (jshell 10.0.1):
jshell> UUID.fromString("1-1-1-1-1")
$2 ==> 00000001-0001-0001-0001-000000000001
Yet the input format does not match what is described in the toString doc.
Also, here is another example where the input is accepted perversely:
jshell> UUID.fromString("5-4-3-DEADBEEF0002-9000000001")
$3 ==> 00000005-0004-0003-0002-009000000001
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
UUID.fromString("5-4-3-DEADBEEF0002-9000000001")
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
an IllegalArgumentException should be thrown
ACTUAL -
UUID object '00000005-0004-0003-0002-009000000001' is returned
---------- BEGIN SOURCE ----------
import java.util.UUID;
class Test{
public static void main(String[] args) throws Exception{
String input="5-4-3-DEADBEEF0002-9000000001";
System.out.println("Calling UUID.fromString with input: "+input);
try{
UUID uuid=UUID.fromString(input);
throw new Exception("Expected IllegalArgumentException exception but got: "+uuid );
}catch(IllegalArgumentException e){
System.out.println("OK: caught exception: "+e);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The only workaround is to manually validate UUID format before calling UUID.fromString
- duplicates
-
JDK-8219815 UUID.fromString() is too lax
- Closed
- relates to
-
JDK-8165199 UUID.fromString accepts wrong placements of the dashes
- Open
-
JDK-8159339 UUID:fromString() parses incorrect strings without error
- Closed
-
JDK-8182452 UUID.fromString accepts invalid UUIDs or throws wrong exception
- Closed
-
JDK-8188902 UUID.fromString does not work as expected
- Closed
-
JDK-8202760 UUID.fromString() accepts invalid (short) strings
- Closed
- links to
(1 relates to, 2 links to)