Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 362529 - [compiler][null] Null pointer warning shown in error
Summary: [compiler][null] Null pointer warning shown in error
Status: RESOLVED DUPLICATE of bug 453483
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7.1   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.5 M4   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard: To be verified for 4.5 M6
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-31 16:08 EDT by Gary Karasiuk CLA
Modified: 2015-02-15 17:12 EST (History)
4 users (show)

See Also:


Attachments
screenshot that shows the error (14.37 KB, image/gif)
2011-10-31 16:15 EDT, Gary Karasiuk CLA
no flags Details
screenshot with the if statement removed (11.88 KB, image/gif)
2011-10-31 16:17 EDT, Gary Karasiuk CLA
no flags Details
screenshot of small test class (17.18 KB, image/gif)
2011-11-02 08:46 EDT, Gary Karasiuk CLA
no flags Details
screenshot of strange fix (9.48 KB, image/gif)
2011-11-02 08:49 EDT, Gary Karasiuk CLA
no flags Details
example source file (611 bytes, text/plain)
2015-02-15 17:12 EST, Stephan Herrmann CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gary Karasiuk CLA 2011-10-31 16:08:51 EDT
Build Identifier: 3.7.1 - Build id: M20110909-1335

I am getting the following warning, when I shouldn't. 

Description	Resource	Path	Location	Type
Null pointer access: The variable cb can only be null at this location	Fixup.java	/ContactsRPS/src/org/runnymedecouncil/contacts	line 42	Java Problem

I will attach two screenshots, one that shows the warning, and one that shows that the warning goes away when I deleted the if statement.


Reproducible: Always
Comment 1 Gary Karasiuk CLA 2011-10-31 16:15:44 EDT
Created attachment 206239 [details]
screenshot that shows the error

You will notice from this screenshot, that there is a similar fragment of code (that is above the code that is in error), that doesn't have the warning.
Comment 2 Gary Karasiuk CLA 2011-10-31 16:17:06 EDT
Created attachment 206240 [details]
screenshot with the if statement removed

If I remove the if statement, the warning goes away.
Comment 3 Stephan Herrmann CLA 2011-11-01 16:42:28 EDT
I briefly tried this in 3.8M3 but failed to reproduce.

I can take a closer look once I'm back from EclipseCon.
Meanwhile, perhaps you could attach a small self-contained sample 
program showing the bug?
Comment 4 Ayushman Jain CLA 2011-11-02 03:11:51 EDT
(In reply to comment #3)
> I briefly tried this in 3.8M3 but failed to reproduce.
> 
Even with 3.7.1 I couldn't reproduce. Must be something specific in Gary's test case.
Comment 5 Gary Karasiuk CLA 2011-11-02 08:38:57 EDT
(In reply to comment #3)
> I briefly tried this in 3.8M3 but failed to reproduce.
> 
> I can take a closer look once I'm back from EclipseCon.
> Meanwhile, perhaps you could attach a small self-contained sample 
> program showing the bug?

I doubt that I can create a small self-contained sample that still illustrates the problem. I can send you my workspace if that would help you. This is the only warning in the entire workspace :-)

I tried simplifying the class and it still shows the problem. I atatched a screenshot.
Comment 6 Gary Karasiuk CLA 2011-11-02 08:46:36 EDT
Created attachment 206320 [details]
screenshot of small test class
Comment 7 Gary Karasiuk CLA 2011-11-02 08:49:21 EDT
Created attachment 206321 [details]
screenshot of strange fix

Notice that if I comment out the line that is below the problem section, the warning goes away.
Comment 8 Ayushman Jain CLA 2011-11-02 08:52:06 EDT
(In reply to comment #7)
Thanks for the screenshots. The foreach loop and the last line give better clarity. 

Please try to post the snippet here rather than just the screenshot. Its easier for someone to copy paste that and test it out. :)
Comment 9 Stephan Herrmann CLA 2015-02-15 17:09:59 EST
Up-to 4.5M3 (incl) we report:

----------
1. WARNING in /tmp/BugTest.java (at line 10)
        if (cb == null) cb = contact.asBuilder();
            ^^
Redundant null check: The variable cb can only be null at this location
----------
2. WARNING in /tmp/BugTest.java (at line 16)
        cb.toString();
        ^^
Null pointer access: The variable cb can only be null at this location
----------

The first warning is correct, the second is not.

Starting with 4.5M4 the incorrect warning is no longer issued.

*** This bug has been marked as a duplicate of bug 453483 ***
Comment 10 Stephan Herrmann CLA 2015-02-15 17:12:06 EST
Created attachment 250809 [details]
example source file

(In reply to Ayushman Jain from comment #8)
> Please try to post the snippet here rather than just the screenshot. Its
> easier for someone to copy paste that and test it out. :)

Yes! :)

In that vein, here's the source file I used for testing.