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.
Created attachment 162648 [details] Screenshot showing the hint Product Version: NetBeans IDE 8.1 (Build 201510222201) Updates: NetBeans IDE is updated to version NetBeans 8.1 Patch 1 Java: 1.8.0_45; Java HotSpot(TM) 64-Bit Server VM 25.45-b02 Runtime: Java(TM) SE Runtime Environment 1.8.0_45-b15 System: Windows 7 version 6.1 running on amd64; UTF-8; en_GB (nb) User directory: C:\Users\quaglan\AppData\Roaming\NetBeans\8.1 Cache directory: C:\Users\quaglan\AppData\Local\NetBeans\Cache\8.1 I stumbled against the following case: If I write: public static boolean equals(List<String> a, List<String> b) { if (a == null && b == null) { return true; } if (a == null && b.isEmpty()) { return true; } if (b == null && a.isEmpty()) { return true; } ... I get a hint about dereferencing a possible null pointer on the third if, even though it can be statically determined that this cannot happen since the first if already handles the case in which both a and b are null.
You can have a = null; b = is non-empty list. First if - if (a == null && b == null) will no pass since b is not null Second if if (a == null && b.isEmpty()) { will no pass since b is not empty Third if if (b == null && a.isEmpty()) { will throw nullpointer exception. You can fix this by changing first if to if (a == null || b == null)
Wait a sec: if (a == null && b == null) { return true; } if (a == null && b.isEmpty()) { return true; } //the expressions are evaluated from left to right and are short circuited //so, if (b == null) I know a is not null otherwise I would not be here // if (b = non-empty list) I do not need to evaluate a.isEmpty() if (b == null && a.isEmpty()) { return true; }
Ok, sorry, you are right. Sending to java hints.