Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Possible NullPointerException in ReactiveMongoSessionRepository #220

Open
thko79 opened this issue Dec 15, 2021 · 0 comments
Open

Possible NullPointerException in ReactiveMongoSessionRepository #220

thko79 opened this issue Dec 15, 2021 · 0 comments

Comments

@thko79
Copy link

thko79 commented Dec 15, 2021

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:

return findSession(id) //
.map(document -> convertToSession(this.mongoSessionConverter, document)) //
.filter(mongoSession -> !mongoSession.isExpired()) //
.switchIfEmpty(Mono.defer(() -> this.deleteById(id).then(Mono.empty())));

As you can see the result of convertToSession is nullable:

@Nullable
static MongoSession convertToSession(AbstractMongoSessionConverter mongoSessionConverter, Document session) {
return (MongoSession) mongoSessionConverter.convert(session, TypeDescriptor.valueOf(Document.class),
TypeDescriptor.valueOf(MongoSession.class));
}

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:

try {
MongoSession mongoSession = this.objectMapper.readValue(json, MongoSession.class);
mongoSession.setExpireAt(expireAt);
return mongoSession;
} catch (IOException e) {
LOG.error("Error during Mongo Session deserialization", e);
return null;
}

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant