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.
"Unnecessary test for null" hint is shown for the following code (at "a != null"): public void xxx(long[] a, long[] b) { if ((a == null) ^ (b == null)) { throw new Error("a and b should be both null or not null."); } if (a != null && a.length != b.length) { throw new Error("a.length != b.length"); } }
reprducible
The same error occures for the following code public void aFunction (Object a, Object b) { if (a == null ? b == null : b != null) { return; } if (a == null) { // unnecessary test for null appears here // do something } } If a is null and b not, the first test is false and the second is necessary. If I rewrite the first test as if ((a == null && b == null) || (a != null && b != null)) { The warning disappears but the value of a is tested twice
*** Bug 251969 has been marked as a duplicate of this bug. ***
*** Bug 247446 has been marked as a duplicate of this bug. ***
The case in the original description is not possible to solve with the current algoritm. The 2nd case could be fixed though.
Fixed in the experimental impl; wait for the umbrella issue to close.