Bug 382789 - [compiler][null] warn when syntactically-nonnull expression is compared against null
Summary: [compiler][null] warn when syntactically-nonnull expression is compared again...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.3 M5   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 331649
Blocks:
  Show dependency tree
 
Reported: 2012-06-16 10:58 EDT by Stephan Herrmann CLA
Modified: 2013-03-12 06:20 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2012-06-16 10:58:35 EDT
Work on bug 331649 revealed that some (silly) situations like this

  if (new Object() == null) 

are not reported by our null analysis.

Tests can already be found in http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/tree/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java?h=sherrmann/NullAnnotationsForFields
as testExpressions0?()

AST classes affected:
- AllocationExpression 
- ArrayAllocationExpression 
- ArrayInitializer
- ClassLiteralAccess
- ThisReference
- Literal

on a related notion also ConditionalExpression with known nullness are
not yet included in this reporting, either.
Comment 1 Stephan Herrmann CLA 2012-06-16 10:59:55 EDT
Marking dependency on bug 331649 because I have an implementation based on
the code from the other bug's patch.
Comment 2 Stephan Herrmann CLA 2012-06-16 12:54:12 EDT
Proposed patch has been pushed via commit http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=sherrmann/NullAnnotationsForFields2&id=3707414526fb14321da557f260d263fece724e8c into the topic branch for bug 331649
Comment 3 Ayushman Jain CLA 2012-06-25 01:51:38 EDT
This can also be pushed into master sometime soon since it is a missing piece of the vanilla null analysis too. Stephan, will the needImplementation(..) depend on the null annotation code? Ideally, it shouldn't right?
Comment 4 Stephan Herrmann CLA 2012-06-25 12:01:45 EDT
(In reply to comment #3)
> This can also be pushed into master sometime soon since it is a missing piece
> of the vanilla null analysis too. Stephan, will the needImplementation(..)
> depend on the null annotation code? Ideally, it shouldn't right?

Yes, maybe this patch could indeed be easily isolated from bug 331649 if desired.
(The needImplementation() was added only to mark that the intention is that the preceeding if-else-if cascade above *should* be complete now, thus, entering the final else is a bug which I want to get reported.)

OTOH, if we'll soon continue the more general discussion, maybe we can move the implementation into master in larger chunks even?
Comment 5 Ayushman Jain CLA 2012-06-25 15:33:21 EDT
(In reply to comment #4)
> (In reply to comment #3)
> > This can also be pushed into master sometime soon since it is a missing piece
> > of the vanilla null analysis too. Stephan, will the needImplementation(..)
> > depend on the null annotation code? Ideally, it shouldn't right?
> 
> Yes, maybe this patch could indeed be easily isolated from bug 331649 if
> desired.
> (The needImplementation() was added only to mark that the intention is that the
> preceeding if-else-if cascade above *should* be complete now, thus, entering
> the final else is a bug which I want to get reported.)
> 
> OTOH, if we'll soon continue the more general discussion, maybe we can move the
> implementation into master in larger chunks even?

Yeah we sure can, but with the impending Java 8 work, I do not know how much time that may take. This particular bug fix, however, should be easily releasable in one of the early milestones in parallel with the work.
Comment 6 Stephan Herrmann CLA 2013-01-22 14:41:37 EST
Released for 4.3 M5 via commit a846071c58f9098177eef02be0134294158f9c4f together with the fix for bug 331649 et al.
Comment 7 shankha banerjee CLA 2013-03-12 05:21:20 EDT
Verified on Windows with 4.2.1 build (we do not see a warning message with the following code. 

public void zoo() {
		if (new Barx () == null) {
		System.out.println("Hello y");
		}
		System.out.println("Hello x");
	}

With the below mentioned build we do see a warning message. 

Verified for 4.3 M6 using  build I20130310-2000