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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java (-3 / +6 lines)
Lines 83-90 Link Here
83
			mergedInfo = trueFlowInfo.addPotentialInitializationsFrom(falseFlowInfo);
83
			mergedInfo = trueFlowInfo.addPotentialInitializationsFrom(falseFlowInfo);
84
		} else if (isConditionOptimizedFalse) {
84
		} else if (isConditionOptimizedFalse) {
85
			mergedInfo = falseFlowInfo.addPotentialInitializationsFrom(trueFlowInfo);
85
			mergedInfo = falseFlowInfo.addPotentialInitializationsFrom(trueFlowInfo);
86
		} else {
86
		} else if (this.resolvedType == TypeBinding.BOOLEAN) {
87
			// if ((t && (v = t)) ? t : t && (v = f)) r = v;  -- ok
87
			// if ((t && (v = t)) ? t : t && (v = f)) r = v;  -- ok
88
			// if (b ? false : (true && (v = false))) return v; -- ok
88
			cst = this.optimizedIfTrueConstant;
89
			cst = this.optimizedIfTrueConstant;
89
			boolean isValueIfTrueOptimizedTrue = cst != null && cst != Constant.NotAConstant && cst.booleanValue() == true;
90
			boolean isValueIfTrueOptimizedTrue = cst != null && cst != Constant.NotAConstant && cst.booleanValue() == true;
90
			boolean isValueIfTrueOptimizedFalse = cst != null && cst != Constant.NotAConstant && cst.booleanValue() == false;
91
			boolean isValueIfTrueOptimizedFalse = cst != null && cst != Constant.NotAConstant && cst.booleanValue() == false;
Lines 113-118 Link Here
113
				FlowInfo.conditional(
114
				FlowInfo.conditional(
114
					trueInfoWhenTrue.mergedWith(falseInfoWhenTrue),
115
					trueInfoWhenTrue.mergedWith(falseInfoWhenTrue),
115
					trueInfoWhenFalse.mergedWith(falseInfoWhenFalse));
116
					trueInfoWhenFalse.mergedWith(falseInfoWhenFalse));
117
		} else {
118
			mergedInfo = FlowInfo.conditional(trueFlowInfo, falseFlowInfo);
116
		}
119
		}
117
		this.mergedInitStateIndex =
120
		this.mergedInitStateIndex =
118
			currentScope.methodScope().recordInitializationStates(mergedInfo);
121
			currentScope.methodScope().recordInitializationStates(mergedInfo);
Lines 314-321 Link Here
314
		}
317
		}
315
		return this.valueIfFalse.nullStatus(flowInfo);
318
		return this.valueIfFalse.nullStatus(flowInfo);
316
	}
319
	}
317
	int ifTrueNullStatus = this.valueIfTrue.nullStatus(flowInfo),
320
	int ifTrueNullStatus = this.valueIfTrue.nullStatus(flowInfo.initsWhenTrue()),
318
	    ifFalseNullStatus = this.valueIfFalse.nullStatus(flowInfo);
321
	    ifFalseNullStatus = this.valueIfFalse.nullStatus(flowInfo.initsWhenFalse());
319
	if (ifTrueNullStatus == ifFalseNullStatus) {
322
	if (ifTrueNullStatus == ifFalseNullStatus) {
320
		return ifTrueNullStatus;
323
		return ifTrueNullStatus;
321
	}
324
	}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java (-5 / +3 lines)
Lines 72-82 Link Here
72
		this.initialization.checkNPE(currentScope, flowContext, flowInfo);
72
		this.initialization.checkNPE(currentScope, flowContext, flowInfo);
73
	}
73
	}
74
	
74
	
75
	flowInfo =
75
	FlowInfo unflattenedInfo = this.initialization.analyseCode(currentScope, flowContext, flowInfo);
76
		this.initialization
76
	flowInfo = unflattenedInfo.unconditionalInits();
77
			.analyseCode(currentScope, flowContext, flowInfo)
77
	int nullStatus = this.initialization.nullStatus(unflattenedInfo);
78
			.unconditionalInits();
79
	int nullStatus = this.initialization.nullStatus(flowInfo);
80
	if (!flowInfo.isDefinitelyAssigned(this.binding)){// for local variable debug attributes
78
	if (!flowInfo.isDefinitelyAssigned(this.binding)){// for local variable debug attributes
81
		this.bits |= FirstAssignmentToLocal;
79
		this.bits |= FirstAssignmentToLocal;
82
	} else {
80
	} else {
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (-1 / +57 lines)
Lines 42-48 Link Here
42
// Only the highest compliance level is run; add the VM argument
42
// Only the highest compliance level is run; add the VM argument
43
// -Dcompliance=1.4 (for example) to lower it if needed
43
// -Dcompliance=1.4 (for example) to lower it if needed
44
static {
44
static {
45
//		TESTS_NAMES = new String[] { "testBug325229" };
45
		TESTS_NAMES = new String[] { "testBug324178" };
46
//		TESTS_NUMBERS = new int[] { 561 };
46
//		TESTS_NUMBERS = new int[] { 561 };
47
//		TESTS_RANGE = new int[] { 1, 2049 };
47
//		TESTS_RANGE = new int[] { 1, 2049 };
48
}
48
}
Lines 14060-14063 Link Here
14060
		},
14060
		},
14061
		"");
14061
		"");
14062
}
14062
}
14063
// Bug 324178 - [null] ConditionalExpression.nullStatus(..) doesn't take into account the analysis of condition itself
14064
public void testBug324178() {
14065
	this.runConformTest(
14066
		new String[] {
14067
			"Bug324178.java",
14068
			"public class Bug324178 {\n" +
14069
			"    boolean b;\n" + 
14070
			"    void foo(Object u) {\n" + 
14071
			"    if (u == null) {}\n" + 
14072
			"        Object o = (u == null) ? new Object() : u;\n" + 
14073
			"        o.toString();   // Incorrect potential NPE\n" + 
14074
			"    }\n" + 
14075
			"}\n"			
14076
		},
14077
		"");
14078
}
14079
// Bug 324178 - [null] ConditionalExpression.nullStatus(..) doesn't take into account the analysis of condition itself
14080
// definite assignment along all true-yielding paths is sufficient
14081
public void testBug324178b() {
14082
	this.runConformTest(
14083
		new String[] {
14084
			"Bug324178.java",
14085
			"public class Bug324178 {\n" +
14086
			"	 boolean foo(boolean b) {\n" +
14087
			"        boolean v;\n" +
14088
			"        if (b ? false : (true && (v = false)))\n" +
14089
			"            return v;\n" + // OK to read v!
14090
			"        return false;\n" +
14091
			"    }\n" +
14092
			"    public static void main(String[] args) {\n" +
14093
			"        System.out.print(new Bug324178().foo(false));\n" +
14094
			"    }\n" +
14095
			"}\n"
14096
		},
14097
		"false");
14098
}
14099
// Bug 324178 - [null] ConditionalExpression.nullStatus(..) doesn't take into account the analysis of condition itself
14100
// definite assignment along all true-yielding paths is sufficient
14101
public void testBug324178c() {
14102
	this.runConformTest(
14103
		new String[] {
14104
			"Bug324178.java",
14105
			"public class Bug324178 {\n" +
14106
			"	 boolean foo() {\n" +
14107
			"        boolean r=false;" +
14108
			"        boolean v;\n" +
14109
			"        if ((true && (v = true)) ? true : true && (v = false)) r = v;\n" +
14110
			"        return r;\n" +
14111
			"    }\n" +
14112
			"    public static void main(String[] args) {\n" +
14113
			"        System.out.print(new Bug324178().foo());\n" +
14114
			"    }\n" +
14115
			"}\n"
14116
		},
14117
		"true");
14118
}
14063
}
14119
}

Return to bug 324178