Bug 248040 - [compiler][null] Fake Potential Null Pointer Access triggered by check against null.
Summary: [compiler][null] Fake Potential Null Pointer Access triggered by check agains...
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-09-20 01:08 EDT by Rodolfo Federico Gamarra CLA
Modified: 2011-03-08 00:59 EST (History)
2 users (show)

See Also:


Attachments
Different test cases showing where the problem happens and where it doesn't. (3.17 KB, text/plain)
2008-09-20 01:08 EDT, Rodolfo Federico Gamarra CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rodolfo Federico Gamarra CLA 2008-09-20 01:08:39 EDT
Created attachment 113055 [details]
Different test cases showing where the problem happens and where it doesn't.

Build ID: I20080617-2000

Steps To Reproduce:
1.Enable: Java->Compiler->Error/Warnings: "Potential Null Pointer Access".
2. Use an expression != against some reference variable.
3. Call a method on the reference variable after the former expression.
Outcome:
A Warning/Error is issue despite.

More information:
This issue is related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=198157.

I believe that this is a little different because this isn't just a "variable correlation" issue.

It seems that a comparison with null is enough to trigger the Warning/Error in some circumtances.

The problem isn't important because I guess that by saying "Potential" (and existing another definite null pointer access category) it's intended to make clear that there can be wrong positives, as this case. 

I'll attach a source file with some examples.
Comment 1 Stephan Herrmann CLA 2011-02-28 07:19:11 EST
I'm inclined to closing as INVALID, because:

caseA: *is* a variable correlation issue despite comment 0

caseE, caseF: the position of "a != null" is irrelevant, relevant is that the
   expression signals that there is uncertainty regarding a's null status


All other cases behave as expected.
Comment 2 Stephan Herrmann CLA 2011-03-04 15:20:48 EST
Closing as per comment 1.

The correlation issue persists, but we have several other bugs for that
(search for [null][correlation] in the bug title).
Comment 3 Ayushman Jain CLA 2011-03-07 05:22:22 EST
Verified for 3.7M6 using build 20110301-1537.

> The problem isn't important because I guess that by saying "Potential" (and
> existing another definite null pointer access category) it's intended to make
> clear that there can be wrong positives, as this case. 

Rodolfo, please not that the "potential" is not added to to make the user aware of a wrong warning. A 'potential' is added to indicate that the variable being warned against is evaluated to null in one of the branches that lead us to the current line of code, whereas when all branches evaluate the variable to null, we omit the 'potential'. A wrong potential null access warning should be reported as a bug and has to be fixed. Thanks!
Comment 4 Rodolfo Federico Gamarra CLA 2011-03-07 10:02:23 EST
Hi all, thanks for going through this. I have some comments, so as to try to grasp the behaviour.

In comment 3:
"A 'potential' is added to indicate that the variable being
warned against is evaluated to null in one of the branches that lead us to the
current line of code"

I don't see that is exactly like that, "a" is never made null (i.e. a = null;).

Ok, so case (a) is a correlation issue. 

In comment 1:

"caseE, caseF: the position of "a != null" is irrelevant, relevant is that the
  expression signals that there is uncertainty regarding a's null status"

0k. 

Cheers, to all. Thanks.
Comment 5 Ayushman Jain CLA 2011-03-08 00:40:18 EST
(In reply to comment #4)
> I don't see that is exactly like that, "a" is never made null (i.e. a = null;).

Not explicitly, but note that a is compared against null in boolean isNotNull = a != null - thus casting a doubt on the nullness of a. Hence the pot. NPE warning.
Comment 6 Rodolfo Federico Gamarra CLA 2011-03-08 00:59:06 EST
(In reply to comment #5)
> (In reply to comment #4)
> > I don't see that is exactly like that, "a" is never made null (i.e. a = null;).
> 
> Not explicitly, but note that a is compared against null in boolean isNotNull =
> a != null - thus casting a doubt on the nullness of a. Hence the pot. NPE
> warning.

Ok, sure, indeed is checked against null: just wanted to clarify that null wasn't assigned to a. So the only presence of that check is enough, as you say, to cast some doubts about its nullness.

Cheers and thanks a lot.