Happy New Year!
The order of the null-check should not have any impact, because this should be handled correctly by our engine. On my machine, with the very same example, it does not change anything.
Thanks a lot for pointing this out. It allowed me to realize what was missing! The root cause of the issue is indeed tied to the
Looking at its code, it uses the JSR-305 annotation
javax.annotation.Nonnull(when = When.MAYBE) as meta-annotation (and with the awfully-counterintuitive notation
When.MAYBE). This use case is handled correctly by our engine, at the condition that the jar of JSR-305 is provided has dependency to the analysis!
In my test-project, I was using Guava, which provides the jar by transitivity… making issues disappear because the semantic of the mongodb annotation was correctly deduced. When exludiing the jar, the FPs now appears.
Now, regarding the fix, I created the following ticket to add the annotation to the whitelist: SONARJAVA-3654.
On your side (probably also apply to @Daniel_Greening ), and while you are waiting for the fix to be shipped, a workaround is to make sure that the JSR-305 jar is provided for the analysis.