spring-session-data-mongodb icon indicating copy to clipboard operation
spring-session-data-mongodb copied to clipboard

Possible NullPointerException in ReactiveMongoSessionRepository

Open thko79 opened this issue 4 years ago • 0 comments

Hi, we had recently some errors in our application after refactoring some package names. We ended up in our research in this code line:

There you apply a filter on a nullable object. Maybe you have to filter Objects::nonNull before apply other filters, see following line: https://github.com/spring-projects/spring-session-data-mongodb/blob/60883711b2635335e4d74daa1f62e2c27a122ebf/src/main/java/org/springframework/session/data/mongo/ReactiveMongoSessionRepository.java#L115-L118

As you can see the result of convertToSession is nullable: https://github.com/spring-projects/spring-session-data-mongodb/blob/60883711b2635335e4d74daa1f62e2c27a122ebf/src/main/java/org/springframework/session/data/mongo/MongoSessionUtils.java#L36-L41

You can reproduce it by placing an invalid Document, this'll cause the ObjectMapper to throw an IOException, which is caught and null value is returned: https://github.com/spring-projects/spring-session-data-mongodb/blob/60883711b2635335e4d74daa1f62e2c27a122ebf/src/main/java/org/springframework/session/data/mongo/JacksonMongoSessionConverter.java#L134-L141

In our case the Documents gets invalid by refactoring of package names, so it does not match any more with the "@class" attribute.

Greetings Thomas

thko79 avatar Dec 15 '21 15:12 thko79