Skip to content

Commit 1a682a5

Browse files
committed
DATAMONGO-2044 make ensureNotIterable actually check if object is iterable
1 parent 6728191 commit 1a682a5

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,13 @@
151151
* @author Borislav Rangelov
152152
* @author duozhilin
153153
* @author Andreas Zink
154+
* @author Bartłomiej Mazur
154155
*/
155156
@SuppressWarnings("deprecation")
156157
public class MongoTemplate implements MongoOperations, ApplicationContextAware, IndexOperationsProvider {
157158

158159
private static final Logger LOGGER = LoggerFactory.getLogger(MongoTemplate.class);
159160
private static final WriteResultChecking DEFAULT_WRITE_RESULT_CHECKING = WriteResultChecking.NONE;
160-
private static final Collection<String> ITERABLE_CLASSES;
161-
162-
static {
163-
164-
Set<String> iterableClasses = new HashSet<>();
165-
iterableClasses.add(List.class.getName());
166-
iterableClasses.add(Collection.class.getName());
167-
iterableClasses.add(Iterator.class.getName());
168-
169-
ITERABLE_CLASSES = Collections.unmodifiableCollection(iterableClasses);
170-
}
171161

172162
private final MongoConverter mongoConverter;
173163
private final MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext;
@@ -1150,7 +1140,7 @@ public <T> T insert(T objectToSave, String collectionName) {
11501140

11511141
protected void ensureNotIterable(@Nullable Object o) {
11521142
if (null != o) {
1153-
if (o.getClass().isArray() || ITERABLE_CLASSES.contains(o.getClass().getName())) {
1143+
if (o.getClass().isArray() || (o instanceof Iterable) || (o instanceof Iterator)) {
11541144
throw new IllegalArgumentException("Cannot use a collection here.");
11551145
}
11561146
}

0 commit comments

Comments
 (0)