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.

Bug 237783

Summary: Dereferencing null pointer hint fails when not using short circuit operands
Product: java Reporter: dktcoding
Component: HintsAssignee: Svata Dedic <sdedic>
Status: RESOLVED FIXED    
Severity: normal Keywords: NO74, USABILITY
Priority: P3    
Version: 7.4   
Hardware: PC   
OS: Linux   
Issue Type: DEFECT Exception Reporter:

Description dktcoding 2013-10-30 03:30:00 UTC
I prepared the following snippet to help understand the problem:

0    public void function(int[] array1, int[] array2){
1       if (array1 == null | array2 == null){
2            throw new NullPointerException();
3        }
4        if (array1.length != array2.length){
5            //Do something
6        }
7    }

In that code the "Dereferencing null pointer" hint appears on line 4, but if in line 2 we use the short circuit operand || the hint goes away. 
Anyway it's impossible for a NullPointerException to be thrown on line 4 using either | or ||.

Regards

Product Version = NetBeans IDE 7.4 (Build 201310111528)
Operating System = Linux version 3.11.0-12-generic running on amd64
Java; VM; Vendor = 1.7.0_45
Runtime = Java HotSpot(TM) 64-Bit Server VM 24.45-b08
Comment 1 Jiri Prox 2013-10-30 14:09:10 UTC
reproducible
Comment 2 Svata Dedic 2013-10-30 15:18:26 UTC
An additional defect:

boolean foo = array1 != null;

if (array.length == 1) {  // <- a warning appears, provoked by array1 != null.
}

speculative values created by == and != comparison operators leak to a permanent variable state set.
Comment 3 Svata Dedic 2013-10-30 15:37:23 UTC
OK, correction ;) Lahvac reminded me that != or == may be seen as a hint that the programmer supposes the value *might* be sometimes null; so values which are subject to != or == operator should be checked as if null was a possible value. So my example is incorrect - not a bug.
Comment 4 Svata Dedic 2013-11-20 14:00:28 UTC
Fixed in http://hg.netbeans.org/jet-main/rev/4db3851709d0