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 240643 - Unnecessary null pointer dereference hint after do{...}while(var==null) construct.
Summary: Unnecessary null pointer dereference hint after do{...}while(var==null) const...
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.4
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-18 14:49 UTC by --VoltagE--
Modified: 2014-01-22 02:34 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Example to show the detection bug. (1.46 KB, text/x-java)
2014-01-18 14:49 UTC, --VoltagE--
Details

Note You need to log in before you can comment on or make changes to this bug.
Description --VoltagE-- 2014-01-18 14:49:03 UTC
Created attachment 144103 [details]
Example to show the detection bug.

The attached code will Hint possible null pointer dereference on the following line: "Class clazz = ex.getClass();"

There is no possibility to get there unless the var==null test returns false, because the loop doesn't contain any break's.

Note! The example is not going to get out of the do{}while loop unless you add an subclass of the Example class and give the name of it when asked. But as that has nothing to do with this problem I left it out.
Comment 1 --VoltagE-- 2014-01-18 15:11:20 UTC
I managed to make the example even smaller.

public class NullDereferenceHint {
    public static void main(String[] args) {
        NullDereferenceHint var;
        do {
            var = createNullDereferenceHint();
            if (var == null) {
                System.out.println("NullDereferenceHint still null!");
            }
        } while (var == null);

        Class clazz = var.getClass();
    }

    public static NullDereferenceHint createNullDereferenceHint() {
        return new NullDereferenceHint();
    }
}

and finally noticed that if I remove these lines (at the end of do{}while loop):
            if (var == null) {
                System.out.println("Example still null!");
            }

The wrong hint goes away.
Comment 2 Svata Dedic 2014-01-20 17:48:42 UTC
Fixed in jet-main#b04c85f5b523
Comment 3 Quality Engineering 2014-01-22 02:34:57 UTC
Integrated into 'main-silver', will be available in build *201401220001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/b04c85f5b523
User: Svata Dedic <sdedic@netbeans.org>
Log: #240643: variable state changed by termination condition pass overrides states from body