View | Details | Raw Unified | Return to bug 354554 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java (+9 lines)
Lines 156-161 Link Here
156
			this.nullStatus = ifTrueNullStatus;
156
			this.nullStatus = ifTrueNullStatus;
157
			return;
157
			return;
158
		}
158
		}
159
		if (trueBranchInfo.reachMode() != FlowInfo.REACHABLE) {
160
			this.nullStatus = ifFalseNullStatus;
161
			return;
162
		}
163
		if (falseBranchInfo.reachMode() != FlowInfo.REACHABLE) {
164
			this.nullStatus = ifTrueNullStatus;
165
			return;
166
		}
167
159
		// is there a chance of null (or non-null)? -> potentially null etc.
168
		// is there a chance of null (or non-null)? -> potentially null etc.
160
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125
169
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125
161
		int status = 0;
170
		int status = 0;
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (+45 lines)
Lines 14898-14901 Link Here
14898
			"----------\n");
14898
			"----------\n");
14899
	}
14899
	}
14900
}
14900
}
14901
// Bug 354554 - [null] conditional with redundant condition yields weak error message
14902
public void testBug354554() {
14903
	this.runNegativeTest(
14904
		new String[] {
14905
			"Bug354554.java",
14906
			"public class Bug354554{\n" +
14907
			"    void foo() {\n" +
14908
			"        Object u = new Object();\n" +
14909
			"        Object r = (u == null ? u : null);\n" + // condition is always false - should not spoil subsequent null-analysis
14910
			"        System.out.println(r.toString());\n" +  // should strongly complain: r is definitely null
14911
			"    }\n" +
14912
			"}\n"
14913
		},
14914
		"----------\n" + 
14915
		"1. ERROR in Bug354554.java (at line 4)\n" + 
14916
		"	Object r = (u == null ? u : null);\n" + 
14917
		"	            ^\n" + 
14918
		"Null comparison always yields false: The variable u cannot be null at this location\n" + 
14919
		"----------\n" + 
14920
		"2. ERROR in Bug354554.java (at line 5)\n" + 
14921
		"	System.out.println(r.toString());\n" + 
14922
		"	                   ^\n" + 
14923
		"Null pointer access: The variable r can only be null at this location\n" + 
14924
		"----------\n");
14925
}
14926
//Bug 354554 - [null] conditional with redundant condition yields weak error message
14927
public void testBug354554b() {
14928
	this.runNegativeTest(
14929
		new String[] {
14930
			"Bug354554.java",
14931
			"public class Bug354554{\n" +
14932
			"    void foo() {\n" +
14933
			"        Object u = new Object();\n" +
14934
			"        Object r = (u != null ? u : null);\n" + // condition is always true - should not spoil subsequent null-analysis
14935
			"        System.out.println(r.toString());\n" +  // don't complain: r is definitely non-null
14936
			"    }\n" +
14937
			"}\n"
14938
		},
14939
		"----------\n" + 
14940
		"1. ERROR in Bug354554.java (at line 4)\n" + 
14941
		"	Object r = (u != null ? u : null);\n" + 
14942
		"	            ^\n" + 
14943
		"Redundant null check: The variable u cannot be null at this location\n" + 
14944
		"----------\n");
14945
}
14901
}
14946
}

Return to bug 354554