[JAVA-143] ObjectID.isValid(String) only checks lower bounds on String Created: 05/Aug/10  Updated: 29/Oct/10  Resolved: 05/Aug/10

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 2.0
Fix Version/s: 2.1

Type: Bug Priority: Major - P3
Reporter: Clint Pells Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File ObjectIDTest.java    

 Description   

ObjectID.isValid(String) will return true for Strings that are longer than are used for building the ObjectID. ObjectID.isValid(String) checks that a String is at least 18 characters long and looks like hex encoding. For hex Strings that are longer than 18 it will also return true. But when constructing the ObjectId(String) it will only use the first 18 characters.

I am expecting that a String that is longer than 18 characters will not be valid as per ObjectID.isValid(String).

This comes up in the context of the Morphia ORM utility that uses ObjectID.isValid(String) when mapping an _id for a DBObject. An exception is thrown when the toString() of the stored ObjectID does not match the String with which the ObjectID was built.



 Comments   
Comment by Scott Hernandez (Inactive) [ 05/Aug/10 ]

That is funny. I patches both morphia and the driver

It will be in the 2.1 release: http://github.com/mongodb/mongo-java-driver/commits/master

Comment by Clint Pells [ 05/Aug/10 ]

Also as morphia bug:
http://code.google.com/p/morphia/issues/detail?id=85

Generated at Thu Feb 08 08:51:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.