Skip to content

ensureNotIterable in MongoTemplate only checks for array type [DATAMONGO-2044] #2911

Closed
@spring-projects-issues

Description

@spring-projects-issues

Bartłomiej Mazur opened DATAMONGO-2044 and commented

Currently code in MongoTemplate only checks if object is an array, but does not check if it is iterable like name is suggesting as it does check if class name of object is inside list that contains class names of iterator, collection and list interfaces - and interface can't be class of object.

That list should be removed and method changed to simple instanceof check. Or just removed.

static {
Set<String> iterableClasses = new HashSet<>();
iterableClasses.add(List.class.getName());
iterableClasses.add(Collection.class.getName());
iterableClasses.add(Iterator.class.getName());
ITERABLE_CLASSES = Collections.unmodifiableCollection(iterableClasses);
}

protected void ensureNotIterable(@Nullable Object o) {
if (null != o) {
if (o.getClass().isArray() || ITERABLE_CLASSES.contains(o.getClass().getName())) {
throw new IllegalArgumentException("Cannot use a collection here.");
}
}
}

 


Referenced from: pull request #590

1 votes, 2 watchers

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions