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 238726

Summary: Null Pointer Dereference hint does not support boolean variables
Product: java Reporter: matthies <matthies>
Component: HintsAssignee: Svata Dedic <sdedic>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 7.4   
Hardware: PC   
OS: Windows 7   
Issue Type: ENHANCEMENT Exception Reporter:
Bug Depends on: 249320    
Bug Blocks:    

Description matthies 2013-11-22 23:36:41 UTC
Example:

    void foo(String text)
    {
        boolean haveText = (text != null && text.length() > 0);
        System.out.println(haveText);
        if (haveText)
        {
            System.out.println(text.toUpperCase());
        }
    }

"Dereferencing possible null pointer" is shown on the toUpperCase() call although clearly 'text' can never be null here.

The warning disappears when moving the condition expression to the 'if' clause, but that is not a solution in situations where the result of the condition test is used multiple times, if one wants to avoid code duplication or if the test may be costly (which are the reasons for storing the result in a boolean variable).
Comment 1 Svata Dedic 2013-11-27 13:11:05 UTC
In order to properly use information from the haveText value expression, one would need to maintain variant sets of null/non null states for variables used in expressions; the current code is not designed that way. 

Will implement if time permits.
Comment 2 Svata Dedic 2015-11-18 08:53:07 UTC
Fixed in the experimental implementation; please wait for the umbrella issue to close.