Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
12.3
-
None
-
None
Description
As posted on NETBEANS-1480, here is another clear example of the fake NullPointerException:
public static void foo(Object bar) {
Objects.requireNonNull(bar, "[bar] must not be null.");
if (bar instanceof String) {
System.out.println(bar.toString());
} else {
throw new IllegalArgumentException("[" + bar.getClass().getSimpleName() + "] not supported.");
}
}
In other words, after the Objects#requireNonNull(Object, String) check, if I do an if-else with an instanceof operator, the "else" section will warn about a NullPointerException (the red method)