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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java (+11 lines)
Lines 318-323 Link Here
318
	if (ifTrueNullStatus == ifFalseNullStatus) {
318
	if (ifTrueNullStatus == ifFalseNullStatus) {
319
		return ifTrueNullStatus;
319
		return ifTrueNullStatus;
320
	}
320
	}
321
	// is there a chance of null? -> potentially null
322
	switch (ifTrueNullStatus) {
323
		case FlowInfo.NULL:
324
		case FlowInfo.POTENTIALLY_NULL:
325
			return FlowInfo.POTENTIALLY_NULL;
326
	}
327
	switch (ifFalseNullStatus) {
328
		case FlowInfo.NULL:
329
		case FlowInfo.POTENTIALLY_NULL:
330
			return FlowInfo.POTENTIALLY_NULL;
331
	}
321
	return FlowInfo.UNKNOWN;
332
	return FlowInfo.UNKNOWN;
322
	// cannot decide which branch to take, and they disagree
333
	// cannot decide which branch to take, and they disagree
323
}
334
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (-7 / +60 lines)
Lines 738-744 Link Here
738
// other path: use a tainted unknown expression status; does not seem to cope well
738
// other path: use a tainted unknown expression status; does not seem to cope well
739
// with o = (o ==  null ? new Object() : o)
739
// with o = (o ==  null ? new Object() : o)
740
// TODO (maxime) https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125
740
// TODO (maxime) https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125
741
public void _test0034_conditional_expression() {
741
public void test0034_conditional_expression() {
742
	this.runNegativeTest(
742
	this.runNegativeTest(
743
		new String[] {
743
		new String[] {
744
			"X.java",
744
			"X.java",
Lines 749-760 Link Here
749
			"    o.toString();\n" +
749
			"    o.toString();\n" +
750
			"  }\n" +
750
			"  }\n" +
751
			"}\n"},
751
			"}\n"},
752
		"----------\n" +
752
			"----------\n" +
753
		"1. ERROR in X.java (at line 4)\n" +
753
			"1. ERROR in X.java (at line 5)\n" +
754
		"	o.toString();\n" +
754
			"	o.toString();\n" +
755
		"	^\n" +
755
			"	^\n" +
756
		"The variable o may be null\n" +
756
			"Potential null pointer access: The variable o may be null at this location\n" +
757
		"----------\n");
757
			"----------\n");
758
}
759
//null analysis -- conditional expression
760
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125
761
//variant with constant condition
762
public void test0034_conditional_expression_2() {
763
	this.runConformTest(
764
		new String[] {
765
			"X.java",
766
			"public class X {\n" +
767
			"  boolean b;\n" +
768
			"  void foo() {\n" +
769
			"    Object o = false ? null : new Object();\n" +
770
			"    o.toString();\n" +
771
			"  }\n" +
772
			"}\n"},
773
			"");
774
}
775
//null analysis -- conditional expression
776
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125
777
//variant with dependency between condition and expression - LocalDeclaration
778
// TODO(stephan) cannot analyse this flow dependency
779
public void _test0034_conditional_expression_3() {
780
	this.runConformTest(
781
		new String[] {
782
			"X.java",
783
			"public class X {\n" +
784
			"  boolean b;\n" +
785
			"  void foo(Object u) {\n" +
786
			"    if (u == null) {}\n" + //taint
787
			"    Object o = (u == null) ? new Object() : u;\n" +
788
			"    o.toString();\n" +
789
			"  }\n" +
790
			"}\n"},
791
			"");
792
}
793
//null analysis -- conditional expression
794
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125
795
//variant with dependency between condition and expression - Assignment
796
//TODO(stephan) cannot analyse this flow dependency
797
public void _test0034_conditional_expression_4() {
798
	this.runConformTest(
799
		new String[] {
800
			"X.java",
801
			"public class X {\n" +
802
			"  boolean b;\n" +
803
			"  void foo(Object u) {\n" +
804
			"    if (u == null) {}\n" + //taint
805
			"    Object o;\n" +
806
			"    o = (u == null) ? new Object() : u;\n" +
807
			"    o.toString();\n" +
808
			"  }\n" +
809
			"}\n"},
810
			"");
758
}
811
}
759
812
760
// null analysis -- conditional expression
813
// null analysis -- conditional expression

Return to bug 133125