Uploaded image for project: 'Spring Data MongoDB'
  1. Spring Data MongoDB
  2. DATAMONGO-1276

MongoTemplate.CloseableIterableCursorAdapter does not null check return values from PersistenceExceptionTranslator.

    Details

    • Sprint:
      SpringOne 2015

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                olivergierke Oliver Gierke
                Reporter:
                kristoffer Kristoffer Peterhänsel
                Last updater:
                Oliver Gierke
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: