Skip to content
Advertisement

Sonar: Possible null pointer dereference due to return value of called method

I am getting issue from Sonar: “Style – Possible null pointer dereference due to return value of called method. findbugs:NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE. the issue is on lockUntil.after(new Date());

JavaScript

I’ve tried to change this issue line with

JavaScript

or

JavaScript

But it introduces other issues.

Can anyone please guide?

Advertisement

Answer

Assuming that new Date() will never return null should be a valid assumption. My guess is that the possibly null value Sonar is complaining about is lockUntil. I assume that queryForObject will return null if the query does not match any rows, so it makes sense that you’d get a complaint about using lockUntil without first checking if it is null.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement