-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.0, 2.1
-
Component/s: None
-
None
-
Environment:All
if you see the ObjectId.java (http://github.com/mongodb/mongo-java-
driver/blob/master/src/main/org/bson/types/ObjectId.java)
isValid(String) method it returns "true" for those strings whose
character length is between 18 and 24 and whose each character happens
to be a qualified hex character.
And then if you see the constructor code, you would notice following
piece of code:
byte b[] = new byte[12];
for ( int i=0; i<b.length; i++ )
Here it expects the string to be of 24 characters.
Hence sometimes though isValid method returns true it cannot create a
valid ObjectId. It throws java.lang.StringIndexOutOfBoundsException:
String index out of range.
This is an important issue as in some cases does not allow to store valid data.