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 (+10 lines)
Lines 11-16 Link Here
11
 *     						bug 133125 - [compiler][null] need to report the null status of expressions and analyze them simultaneously
11
 *     						bug 133125 - [compiler][null] need to report the null status of expressions and analyze them simultaneously
12
 *     						bug 292478 - Report potentially null across variable assignment
12
 *     						bug 292478 - Report potentially null across variable assignment
13
 * 							bug 324178 - [null] ConditionalExpression.nullStatus(..) doesn't take into account the analysis of condition itself
13
 * 							bug 324178 - [null] ConditionalExpression.nullStatus(..) doesn't take into account the analysis of condition itself
14
 * 							bug 354554 - [null] conditional with redundant condition yields weak error message
14
 *******************************************************************************/
15
 *******************************************************************************/
15
package org.eclipse.jdt.internal.compiler.ast;
16
package org.eclipse.jdt.internal.compiler.ast;
16
17
Lines 156-161 Link Here
156
			this.nullStatus = ifTrueNullStatus;
157
			this.nullStatus = ifTrueNullStatus;
157
			return;
158
			return;
158
		}
159
		}
160
		if (trueBranchInfo.reachMode() != FlowInfo.REACHABLE) {
161
			this.nullStatus = ifFalseNullStatus;
162
			return;
163
		}
164
		if (falseBranchInfo.reachMode() != FlowInfo.REACHABLE) {
165
			this.nullStatus = ifTrueNullStatus;
166
			return;
167
		}
168
159
		// is there a chance of null (or non-null)? -> potentially null etc.
169
		// is there a chance of null (or non-null)? -> potentially null etc.
160
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125
170
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125
161
		int status = 0;
171
		int status = 0;
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (+46 lines)
Lines 17-22 Link Here
17
 *     						bug 338303 - Warning about Redundant assignment conflicts with definite assignment
17
 *     						bug 338303 - Warning about Redundant assignment conflicts with definite assignment
18
 *     						bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop
18
 *     						bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop
19
 * 							bug 324178 - [null] ConditionalExpression.nullStatus(..) doesn't take into account the analysis of condition itself
19
 * 							bug 324178 - [null] ConditionalExpression.nullStatus(..) doesn't take into account the analysis of condition itself
20
 * 							bug 354554 - [null] conditional with redundant condition yields weak error message
20
 *******************************************************************************/
21
 *******************************************************************************/
21
package org.eclipse.jdt.core.tests.compiler.regression;
22
package org.eclipse.jdt.core.tests.compiler.regression;
22
23
Lines 14898-14901 Link Here
14898
			"----------\n");
14899
			"----------\n");
14899
	}
14900
	}
14900
}
14901
}
14902
// Bug 354554 - [null] conditional with redundant condition yields weak error message
14903
public void testBug354554() {
14904
	this.runNegativeTest(
14905
		new String[] {
14906
			"Bug354554.java",
14907
			"public class Bug354554{\n" +
14908
			"    void foo() {\n" +
14909
			"        Object u = new Object();\n" +
14910
			"        Object r = (u == null ? u : null);\n" + // condition is always false - should not spoil subsequent null-analysis
14911
			"        System.out.println(r.toString());\n" +  // should strongly complain: r is definitely null
14912
			"    }\n" +
14913
			"}\n"
14914
		},
14915
		"----------\n" + 
14916
		"1. ERROR in Bug354554.java (at line 4)\n" + 
14917
		"	Object r = (u == null ? u : null);\n" + 
14918
		"	            ^\n" + 
14919
		"Null comparison always yields false: The variable u cannot be null at this location\n" + 
14920
		"----------\n" + 
14921
		"2. ERROR in Bug354554.java (at line 5)\n" + 
14922
		"	System.out.println(r.toString());\n" + 
14923
		"	                   ^\n" + 
14924
		"Null pointer access: The variable r can only be null at this location\n" + 
14925
		"----------\n");
14926
}
14927
//Bug 354554 - [null] conditional with redundant condition yields weak error message
14928
public void testBug354554b() {
14929
	this.runNegativeTest(
14930
		new String[] {
14931
			"Bug354554.java",
14932
			"public class Bug354554{\n" +
14933
			"    void foo() {\n" +
14934
			"        Object u = new Object();\n" +
14935
			"        Object r = (u != null ? u : null);\n" + // condition is always true - should not spoil subsequent null-analysis
14936
			"        System.out.println(r.toString());\n" +  // don't complain: r is definitely non-null
14937
			"    }\n" +
14938
			"}\n"
14939
		},
14940
		"----------\n" + 
14941
		"1. ERROR in Bug354554.java (at line 4)\n" + 
14942
		"	Object r = (u != null ? u : null);\n" + 
14943
		"	            ^\n" + 
14944
		"Redundant null check: The variable u cannot be null at this location\n" + 
14945
		"----------\n");
14946
}
14901
}
14947
}

Return to bug 354554