This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Product Version = NetBeans IDE 8.0 (Build 201403101706) Operating System = Linux version 3.11.0-031100-generic running on amd64 Java; VM; Vendor = 1.7.0_55 Runtime = Java HotSpot(TM) 64-Bit Server VM 24.55-b03 Reference the following code: public class NullPointerTest { public void test(String arg1, String arg2) { boolean useArg1 = arg1 != null; if (useArg1) { System.out.println(arg1.length()); // Inappropriate "dereferencing possible null pointer" warning } else { System.out.println(arg2.length()); // *No* "dereferencing possible null pointer" warning } } } The IDE gives a warning on the first length() invocation, saying "dereferencing possible null pointer". This is wrong, as that branch is guarded by a variable which is only true when arg1 is *not* null! The IDE should be able to infer from its flow analysis that arg1 can never be null at that location. And for the second invocation of length(), where the operand *can* be null, it does not give the warning. I assume the warning for arg1 is triggered by the explicit null check on it? If so then it's ironic and not very useful that the actual result is exactly opposite from the intended result... I'm not sure this is a bug. It may just be that Netbeans' flow analysis is not sophisticated enough to detect that arg1 can never be null, but in that case I propose that this hint be turned off by default. I know from my own experience that this construct is relatively common, and right now Netbeans is littering my code with this incorrect warning.
Understood, but requires a different approach to the data flow analysis. See enhancement #226083 *** This bug has been marked as a duplicate of bug 226083 ***