Community
Participate
Working Groups
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.
Marking dependency on bug 331649 because I have an implementation based on the code from the other bug's patch.
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
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?
(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?
(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.
Released for 4.3 M5 via commit a846071c58f9098177eef02be0134294158f9c4f together with the fix for bug 331649 et al.
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