### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java,v retrieving revision 1.100 diff -u -r1.100 ConditionalExpression.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java 4 Mar 2011 21:22:49 -0000 1.100 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java 11 Aug 2011 21:12:34 -0000 @@ -156,6 +156,15 @@ this.nullStatus = ifTrueNullStatus; return; } + if (trueBranchInfo.reachMode() != FlowInfo.REACHABLE) { + this.nullStatus = ifFalseNullStatus; + return; + } + if (falseBranchInfo.reachMode() != FlowInfo.REACHABLE) { + this.nullStatus = ifTrueNullStatus; + return; + } + // is there a chance of null (or non-null)? -> potentially null etc. // https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125 int status = 0; #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java,v retrieving revision 1.120 diff -u -r1.120 NullReferenceTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 28 Jul 2011 17:06:24 -0000 1.120 +++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 11 Aug 2011 21:12:57 -0000 @@ -14898,4 +14898,49 @@ "----------\n"); } } +// Bug 354554 - [null] conditional with redundant condition yields weak error message +public void testBug354554() { + this.runNegativeTest( + new String[] { + "Bug354554.java", + "public class Bug354554{\n" + + " void foo() {\n" + + " Object u = new Object();\n" + + " Object r = (u == null ? u : null);\n" + // condition is always false - should not spoil subsequent null-analysis + " System.out.println(r.toString());\n" + // should strongly complain: r is definitely null + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Bug354554.java (at line 4)\n" + + " Object r = (u == null ? u : null);\n" + + " ^\n" + + "Null comparison always yields false: The variable u cannot be null at this location\n" + + "----------\n" + + "2. ERROR in Bug354554.java (at line 5)\n" + + " System.out.println(r.toString());\n" + + " ^\n" + + "Null pointer access: The variable r can only be null at this location\n" + + "----------\n"); +} +//Bug 354554 - [null] conditional with redundant condition yields weak error message +public void testBug354554b() { + this.runNegativeTest( + new String[] { + "Bug354554.java", + "public class Bug354554{\n" + + " void foo() {\n" + + " Object u = new Object();\n" + + " Object r = (u != null ? u : null);\n" + // condition is always true - should not spoil subsequent null-analysis + " System.out.println(r.toString());\n" + // don't complain: r is definitely non-null + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Bug354554.java (at line 4)\n" + + " Object r = (u != null ? u : null);\n" + + " ^\n" + + "Redundant null check: The variable u cannot be null at this location\n" + + "----------\n"); +} } \ No newline at end of file