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 - Null Pointer Dereference hint does not support boolean variables
Summary: Null Pointer Dereference hint does not support boolean variables
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.4
Hardware: PC Windows 7
: P2 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on: 249320
Blocks:
  Show dependency tree
 
Reported: 2013-11-22 23:36 UTC by matthies
Modified: 2015-11-18 08:53 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.