Hello,
I found a piece of code that is reported as a false positive "Possible null pointer dereference" when checked with Objects.isNull. Curiously It only fails inside a try-with resources:
This fails for me for object 'nullable'
public void findbugs() throws Exception {
try (Closeable b = () -> {
LOG.info("close");
}) {
String nullable = getString();
if (Objects.isNull(nullable)) {
throw new ServletException("aaa");
}
LOG.warn(nullable.toString());
} catch (Exception e) {
LOG.error("eeee", e);
}
}
@CheckForNull
public String getString() {
return (int) (Math.random() * 1000) % 2 == 0 ? "a" : null;
}
but using a simple try works fine:
public void findbugs() throws Exception {
try {
String nullable = getString();
if (Objects.isNull(nullable)) {
throw new ServletException("aaa");
}
LOG.warn(nullable.toString());
} catch (Exception e) {
LOG.error("eeee", e);
}
}
@CheckForNull
public String getString() {
return (int) (Math.random() * 1000) % 2 == 0 ? "a" : null;
}
replacing Objects.isNull for a regular null check also works fine.
This happens using:
findbugs 3.0.1 with the maven plugin 3.0.4
java 1.8.0_65-b17
Greetings.