I have read the issues regarding Objects.requireNonNull, so I expected the following to show no errors (using Spotbugs Maven plugin 4.8.4.0 with Spotbugs 4.8.4).
package foobar;
import java.util.Objects;
import java.util.function.Supplier;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
public class SpotBugsTest {
public void foo() {
final String foo = getString("foo");
Objects.requireNonNull(foo);
}
public void bar() {
final String bar = getString("bar");
Objects.requireNonNull(bar, "Bar must not be null");
}
public void baz() {
final Supplier<String> supplier = ()-> "Baz must not be null";
final String baz = getString("baz");
Objects.requireNonNull(baz, supplier);
}
@CheckForNull
private String getString(@Nullable final String text) {
return text == null ? null : text;
}
}
However, I get Spotbugs errors for all three cases.
<BugInstance type='NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE' priority='Normal' category='STYLE' message='Possible null pointer dereference in ch.ipi.schutztitel.bo.SpotBugsTest.bar() due to return value of called method' lineNumber='18' />
<BugInstance type='NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE' priority='Normal' category='STYLE' message='Possible null pointer dereference in ch.ipi.schutztitel.bo.SpotBugsTest.baz() due to return value of called method' lineNumber='24' />
<BugInstance type='NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE' priority='Normal' category='STYLE' message='Possible null pointer dereference in ch.ipi.schutztitel.bo.SpotBugsTest.foo() due to return value of called method' lineNumber='13' />
I thought this was fixed with the issues I read. Am I doing something wrong?
P.S. Thanks a lot for SpotBugs and carrying the load of work!
I have read the issues regarding
Objects.requireNonNull, so I expected the following to show no errors (using Spotbugs Maven plugin 4.8.4.0 with Spotbugs 4.8.4).However, I get Spotbugs errors for all three cases.
I thought this was fixed with the issues I read. Am I doing something wrong?
P.S. Thanks a lot for SpotBugs and carrying the load of work!