Skip to content

MongoTemplate.CloseableIterableCursorAdapter does not null check return values from PersistenceExceptionTranslator. [DATAMONGO-1276] #2194

@spring-projects-issues

Description

@spring-projects-issues

Kristoffer Peterhänsel opened DATAMONGO-1276 and commented

Using the Stream support in a MongoRepository I suddenly started getting exceptions like these:

java.lang.NullPointerException: null
	at org.springframework.data.mongodb.core.MongoTemplate$CloseableIterableCusorAdapter.next(MongoTemplate.java:2389)
	at java.util.Iterator.forEachRemaining(Iterator.java:116)
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
...

After a bit if investigation it turns out that due to some domain model changes I appear to be getting an org.springframework.data.mapping.model.MappingException in the data mapping and since MongoExceptionTranslator does not specifically know about it. So it just returns null.

That appears to be fine according to the PersistenceExceptionTranslator interface. But it appears that the Spring Data MongoDB code will often throw the result without any null checks. Provoking an NPE and hiding the actual reason for the exception


Affects: 1.7.2 (Fowler SR2)

Issue Links:

  • DATAMONGO-1295 The MongoTemplate.CloseableIterableCusorAdapter runs into an NPE when a MappingException was raised
    ("is duplicated by")
  • DATAMONGO-1307 Stop converting user-defined runtime exceptions to NPEs
    ("is duplicated by")

Backported to: 1.8.1 (Gosling SR1), 1.7.3 (Fowler SR3)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions