Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant