|
When the DBObject.keySet() rerturns a Set<String> that is an instance of StringRangeSet, performing keySet.contains("FOO") on it will throw NumberFormatException.
Caused due to the contains implementation that assume input is a valid number:
@Override
|
public boolean contains(final Object o) {
|
if (!(o instanceof String)) {
|
return false;
|
}
|
int i = Integer.parseInt((String) o);
|
return i >= 0 && i < size();
|
}
|
Using a non-number contains can be a valid use case when recursively iterating through a DBObject, trying to remove all "_class" fields that spring-data-mongo generate:
private void removeClassFields(DBObject dbObject){
|
Set<String> keys = dbObject.keySet();
|
if (keys.contains("_class")){
|
dbObject.removeField("_class");
|
}
|
for (String key : keys) {
|
if (dbObject.get(key) instanceof DBObject){
|
removeClassFields((DBObject) dbObject.get(key));
|
}
|
}
|
}
|
|