Open hgschmie opened 2 years ago
pretty ping?
pretty pretty ping?
I hit the same problem (bug?).
I got rid of the warning by replacing Objects#requireNonNull
with Optional#ofNullable
, which in the end I liked more, because I can control the exception being thrown.
I can still reproduce this bug with spotbugs 4.7.0
another pretty ping. This is now open for 18 months.
Sorry for the belated answer, the project is a bit low on manpower and it is quite complicated as well (it is static flow analysis after all...)
Can you try:
value = requireNonNull(value);
Instead of:
requireNonNull(value);
I've seen elsewhere that SpotBugs knows that the return of requireNonNull
is non null, but it is not smart enough that an exception is thrown otherwise
Hi! Thanks for your proposal, but value = requireNonNull(value);
still triggers spot bugs failure.
This code:
reports
[ERROR] Medium: Possible null pointer dereference in testcode.SpotbugsTest.getMapping(String, String) due to return value of called method [testcode.SpotbugsTest, testcode.SpotbugsTest] Method invoked at SpotbugsTest.java:[line 20]Known null at SpotbugsTest.java:[line 19] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE
Objects#requireNonNull
is supposed to do the null check, but is flagged as dereferencing its parameter.Removing the
@CheckForNull
annotation makes the spotbugs check pass.IntelliJ flow analysis shows this correctly:
(with
requireNonNull
commented out):There is no such warning with the method call.