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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java (+6 lines)
Lines 60-65 Link Here
60
			}
60
			}
61
		}
61
		}
62
		rightInfo = this.right.analyseCode(currentScope, flowContext, rightInfo);
62
		rightInfo = this.right.analyseCode(currentScope, flowContext, rightInfo);
63
		if ((this.left.implicitConversion & TypeIds.UNBOXING) != 0) {
64
			this.left.checkNPE(currentScope, flowContext, flowInfo);
65
		}
66
		if ((this.right.implicitConversion & TypeIds.UNBOXING) != 0) {
67
			this.right.checkNPE(currentScope, flowContext, flowInfo);
68
		}
63
		FlowInfo mergedInfo = FlowInfo.conditional(
69
		FlowInfo mergedInfo = FlowInfo.conditional(
64
				rightInfo.safeInitsWhenTrue(),
70
				rightInfo.safeInitsWhenTrue(),
65
				leftInfo.initsWhenFalse().unconditionalInits().mergedWith(
71
				leftInfo.initsWhenFalse().unconditionalInits().mergedWith(
(-)compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java (+3 lines)
Lines 39-44 Link Here
39
				this.arguments[i]
39
				this.arguments[i]
40
					.analyseCode(currentScope, flowContext, flowInfo)
40
					.analyseCode(currentScope, flowContext, flowInfo)
41
					.unconditionalInits();
41
					.unconditionalInits();
42
			if ((this.arguments[i].implicitConversion & TypeIds.UNBOXING) != 0) {
43
				this.arguments[i].checkNPE(currentScope, flowContext, flowInfo);
44
			}
42
		}
45
		}
43
	}
46
	}
44
	// record some dependency information for exception types
47
	// record some dependency information for exception types
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java (+3 lines)
Lines 30-35 Link Here
30
			Expression dim;
30
			Expression dim;
31
			if ((dim = this.dimensions[i]) != null) {
31
			if ((dim = this.dimensions[i]) != null) {
32
				flowInfo = dim.analyseCode(currentScope, flowContext, flowInfo);
32
				flowInfo = dim.analyseCode(currentScope, flowContext, flowInfo);
33
				if ((dim.implicitConversion & TypeIds.UNBOXING) != 0) {
34
					dim.checkNPE(currentScope, flowContext, flowInfo);
35
				}
33
			}
36
			}
34
		}
37
		}
35
		if (this.initializer != null) {
38
		if (this.initializer != null) {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java (+3 lines)
Lines 42-47 Link Here
42
	this.preAssertInitStateIndex = currentScope.methodScope().recordInitializationStates(flowInfo);
42
	this.preAssertInitStateIndex = currentScope.methodScope().recordInitializationStates(flowInfo);
43
43
44
	Constant cst = this.assertExpression.optimizedBooleanConstant();
44
	Constant cst = this.assertExpression.optimizedBooleanConstant();
45
	if ((this.assertExpression.implicitConversion & TypeIds.UNBOXING) != 0) {
46
		this.assertExpression.checkNPE(currentScope, flowContext, flowInfo);
47
	}
45
	boolean isOptimizedTrueAssertion = cst != Constant.NotAConstant && cst.booleanValue() == true;
48
	boolean isOptimizedTrueAssertion = cst != Constant.NotAConstant && cst.booleanValue() == true;
46
	boolean isOptimizedFalseAssertion = cst != Constant.NotAConstant && cst.booleanValue() == false;
49
	boolean isOptimizedFalseAssertion = cst != Constant.NotAConstant && cst.booleanValue() == false;
47
	
50
	
(-)compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java (+3 lines)
Lines 37-42 Link Here
37
// a field reference, a blank final field reference, a field of an enclosing instance or
37
// a field reference, a blank final field reference, a field of an enclosing instance or
38
// just a local variable.
38
// just a local variable.
39
	LocalVariableBinding local = this.lhs.localVariableBinding();
39
	LocalVariableBinding local = this.lhs.localVariableBinding();
40
	if ((this.expression.implicitConversion & TypeIds.UNBOXING) != 0) {
41
		this.expression.checkNPE(currentScope, flowContext, flowInfo);
42
	}
40
	int nullStatus = this.expression.nullStatus(flowInfo);
43
	int nullStatus = this.expression.nullStatus(flowInfo);
41
	if (local != null && (local.type.tagBits & TagBits.IsBaseType) == 0) {
44
	if (local != null && (local.type.tagBits & TagBits.IsBaseType) == 0) {
42
		if (nullStatus == FlowInfo.NULL) {
45
		if (nullStatus == FlowInfo.NULL) {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java (-1 / +5 lines)
Lines 47-55 Link Here
47
}
47
}
48
48
49
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
49
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
50
	return this.expression
50
	FlowInfo result = this.expression
51
		.analyseCode(currentScope, flowContext, flowInfo)
51
		.analyseCode(currentScope, flowContext, flowInfo)
52
		.unconditionalInits();
52
		.unconditionalInits();
53
	if ((this.expression.implicitConversion & TypeIds.UNBOXING) != 0) {
54
		this.expression.checkNPE(currentScope, flowContext, flowInfo);
55
	}
56
	return result;
53
}
57
}
54
58
55
/**
59
/**
(-)compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java (+12 lines)
Lines 57-62 Link Here
57
57
58
	int previousMode = flowInfo.reachMode();
58
	int previousMode = flowInfo.reachMode();
59
59
60
	FlowInfo initsOnCondition = flowInfo;
61
60
	UnconditionalFlowInfo actionInfo = flowInfo.nullInfoLessUnconditionalCopy();
62
	UnconditionalFlowInfo actionInfo = flowInfo.nullInfoLessUnconditionalCopy();
61
	// we need to collect the contribution to nulls of the coming paths through the
63
	// we need to collect the contribution to nulls of the coming paths through the
62
	// loop, be they falling through normally or branched to break, continue labels
64
	// loop, be they falling through normally or branched to break, continue labels
Lines 72-77 Link Here
72
				FlowInfo.UNREACHABLE) != 0) {
74
				FlowInfo.UNREACHABLE) != 0) {
73
			this.continueLabel = null;
75
			this.continueLabel = null;
74
		}
76
		}
77
		if ((this.condition.implicitConversion & TypeIds.UNBOXING) != 0) {
78
			if ((actionInfo.tagBits & FlowInfo.UNREACHABLE) == 0) { 
79
				initsOnCondition = flowInfo.unconditionalCopy().
80
										addPotentialInitializationsFrom(actionInfo).
81
										addInitializationsFrom(loopingContext.initsOnContinue);
82
			}
83
		}
84
	}
85
	if ((this.condition.implicitConversion & TypeIds.UNBOXING) != 0) {
86
		this.condition.checkNPE(currentScope, flowContext, initsOnCondition);
75
	}
87
	}
76
	/* Reset reach mode, to address following scenario.
88
	/* Reset reach mode, to address following scenario.
77
	 *   final blank;
89
	 *   final blank;
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java (+3 lines)
Lines 76-81 Link Here
76
						this.arguments[i]
76
						this.arguments[i]
77
							.analyseCode(currentScope, flowContext, flowInfo)
77
							.analyseCode(currentScope, flowContext, flowInfo)
78
							.unconditionalInits();
78
							.unconditionalInits();
79
					if ((this.arguments[i].implicitConversion & TypeIds.UNBOXING) != 0) {
80
						this.arguments[i].checkNPE(currentScope, flowContext, flowInfo);
81
					}
79
				}
82
				}
80
			}
83
			}
81
84
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.java (+3 lines)
Lines 92-97 Link Here
92
							new LoopingFlowContext(flowContext, flowInfo, this, null,
92
							new LoopingFlowContext(flowContext, flowInfo, this, null,
93
								null, this.scope)),
93
								null, this.scope)),
94
						condInfo);
94
						condInfo);
95
				if ((this.condition.implicitConversion & TypeIds.UNBOXING) != 0) {
96
					this.condition.checkNPE(currentScope, flowContext, flowInfo);
97
				}
95
			}
98
			}
96
		}
99
		}
97
100
(-)compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java (+3 lines)
Lines 57-62 Link Here
57
	int initialComplaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED;
57
	int initialComplaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED;
58
58
59
	Constant cst = this.condition.optimizedBooleanConstant();
59
	Constant cst = this.condition.optimizedBooleanConstant();
60
	if ((this.condition.implicitConversion & TypeIds.UNBOXING) != 0) {
61
		this.condition.checkNPE(currentScope, flowContext, flowInfo);
62
	}
60
	boolean isConditionOptimizedTrue = cst != Constant.NotAConstant && cst.booleanValue() == true;
63
	boolean isConditionOptimizedTrue = cst != Constant.NotAConstant && cst.booleanValue() == true;
61
	boolean isConditionOptimizedFalse = cst != Constant.NotAConstant && cst.booleanValue() == false;
64
	boolean isConditionOptimizedFalse = cst != Constant.NotAConstant && cst.booleanValue() == false;
62
65
(-)compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java (+3 lines)
Lines 40-45 Link Here
40
	if (this.initialization == null) {
40
	if (this.initialization == null) {
41
		return flowInfo;
41
		return flowInfo;
42
	}
42
	}
43
	if ((this.initialization.implicitConversion & TypeIds.UNBOXING) != 0) {
44
		this.initialization.checkNPE(currentScope, flowContext, flowInfo);
45
	}
43
	int nullStatus = this.initialization.nullStatus(flowInfo);
46
	int nullStatus = this.initialization.nullStatus(flowInfo);
44
	flowInfo =
47
	flowInfo =
45
		this.initialization
48
		this.initialization
(-)compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java (+3 lines)
Lines 65-70 Link Here
65
	if (this.arguments != null) {
65
	if (this.arguments != null) {
66
		int length = this.arguments.length;
66
		int length = this.arguments.length;
67
		for (int i = 0; i < length; i++) {
67
		for (int i = 0; i < length; i++) {
68
			if ((this.arguments[i].implicitConversion & TypeIds.UNBOXING) != 0) {
69
				this.arguments[i].checkNPE(currentScope, flowContext, flowInfo);
70
			}
68
			flowInfo = this.arguments[i].analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
71
			flowInfo = this.arguments[i].analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
69
		}
72
		}
70
	}
73
	}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java (+6 lines)
Lines 62-67 Link Here
62
			}
62
			}
63
		}
63
		}
64
		rightInfo = this.right.analyseCode(currentScope, flowContext, rightInfo);
64
		rightInfo = this.right.analyseCode(currentScope, flowContext, rightInfo);
65
		if ((this.left.implicitConversion & TypeIds.UNBOXING) != 0) {
66
			this.left.checkNPE(currentScope, flowContext, flowInfo);
67
		}
68
		if ((this.right.implicitConversion & TypeIds.UNBOXING) != 0) {
69
			this.right.checkNPE(currentScope, flowContext, flowInfo);
70
		}
65
		// The definitely null variables in right info when true should not be missed out while merging
71
		// The definitely null variables in right info when true should not be missed out while merging
66
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=299900
72
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=299900
67
		FlowInfo leftInfoWhenTrueForMerging = leftInfo.initsWhenTrue().unconditionalCopy().addPotentialInitializationsFrom(rightInfo.unconditionalInitsWithoutSideEffect());
73
		FlowInfo leftInfoWhenTrueForMerging = leftInfo.initsWhenTrue().unconditionalCopy().addPotentialInitializationsFrom(rightInfo.unconditionalInitsWithoutSideEffect());
(-)compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java (+3 lines)
Lines 71-76 Link Here
71
		if (this.arguments != null) {
71
		if (this.arguments != null) {
72
			for (int i = 0, count = this.arguments.length; i < count; i++) {
72
			for (int i = 0, count = this.arguments.length; i < count; i++) {
73
				flowInfo = this.arguments[i].analyseCode(currentScope, flowContext, flowInfo);
73
				flowInfo = this.arguments[i].analyseCode(currentScope, flowContext, flowInfo);
74
				if ((this.arguments[i].implicitConversion & TypeIds.UNBOXING) != 0) {
75
					this.arguments[i].checkNPE(currentScope, flowContext, flowInfo);
76
				}
74
			}
77
			}
75
		}
78
		}
76
79
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java (+3 lines)
Lines 36-41 Link Here
36
36
37
	if (this.expression != null) {
37
	if (this.expression != null) {
38
		flowInfo = this.expression.analyseCode(currentScope, flowContext, flowInfo);
38
		flowInfo = this.expression.analyseCode(currentScope, flowContext, flowInfo);
39
		if ((this.expression.implicitConversion & TypeIds.UNBOXING) != 0) {
40
			this.expression.checkNPE(currentScope, flowContext, flowInfo);
41
		}
39
	}
42
	}
40
	this.initStateIndex =
43
	this.initStateIndex =
41
		currentScope.methodScope().recordInitializationStates(flowInfo);
44
		currentScope.methodScope().recordInitializationStates(flowInfo);
(-)compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java (+3 lines)
Lines 47-52 Link Here
47
	public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
47
	public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
48
		try {
48
		try {
49
			flowInfo = this.expression.analyseCode(currentScope, flowContext, flowInfo);
49
			flowInfo = this.expression.analyseCode(currentScope, flowContext, flowInfo);
50
			if ((this.expression.implicitConversion & TypeIds.UNBOXING) != 0) {
51
				this.expression.checkNPE(currentScope, flowContext, flowInfo);
52
			}
50
			SwitchFlowContext switchContext =
53
			SwitchFlowContext switchContext =
51
				new SwitchFlowContext(flowContext, this, (this.breakLabel = new BranchLabel()));
54
				new SwitchFlowContext(flowContext, this, (this.breakLabel = new BranchLabel()));
52
55
(-)compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java (+3 lines)
Lines 63-68 Link Here
63
					new LoopingFlowContext(flowContext, flowInfo, this, null,
63
					new LoopingFlowContext(flowContext, flowInfo, this, null,
64
						null, currentScope)),
64
						null, currentScope)),
65
				condInfo);
65
				condInfo);
66
		if ((this.condition.implicitConversion & TypeIds.UNBOXING) != 0) {
67
			this.condition.checkNPE(currentScope, flowContext, flowInfo);
68
		}
66
69
67
		LoopingFlowContext loopingContext;
70
		LoopingFlowContext loopingContext;
68
		FlowInfo actionInfo;
71
		FlowInfo actionInfo;
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (+256 lines)
Lines 11662-11665 Link Here
11662
		"----------\n",
11662
		"----------\n",
11663
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
11663
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
11664
}
11664
}
11665
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201
11666
// unboxing raises an NPE
11667
//   LocalDeclaration
11668
public void testBug319201() {
11669
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
11670
		return;
11671
	runNegativeTest(
11672
			new String[] {
11673
				"X.java",
11674
				"public class X {\n" +
11675
				"  public void foo() {\n" +
11676
				"	 Integer i = null;\n" +
11677
				"	 int j = i;\n" + // should warn
11678
				"  }\n" +
11679
				"}"},
11680
			"----------\n" + 
11681
			"1. ERROR in X.java (at line 4)\n" + 
11682
			"	int j = i;\n" + 
11683
			"	        ^\n" + 
11684
			"Null pointer access: The variable i can only be null at this location\n" + 
11685
			"----------\n",
11686
		    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
11687
}
11688
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201
11689
// unboxing could raise an NPE
11690
//   Assignment
11691
public void testBug319201a() {
11692
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
11693
		return;
11694
	runNegativeTest(
11695
			new String[] {
11696
				"X.java",
11697
				"public class X {\n" +
11698
				"  public void foo(Integer i) {\n" +
11699
				"    if (i == null) {};\n" +
11700
				"	 int j;\n" +
11701
				"	 j = i;\n" + // should warn
11702
				"  }\n" +
11703
				"}"},
11704
			"----------\n" + 
11705
			"1. ERROR in X.java (at line 5)\n" + 
11706
			"	j = i;\n" + 
11707
			"	    ^\n" + 
11708
			"Potential null pointer access: The variable i may be null at this location\n" + 
11709
			"----------\n",
11710
		    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
11711
}
11712
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201
11713
// unboxing raises an NPE
11714
//   MessageSend
11715
public void testBug319201b() {
11716
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
11717
		return;
11718
	runNegativeTest(
11719
			new String[] {
11720
				"X.java",
11721
				"public class X {\n" +
11722
				"  public void foo() {\n" +
11723
				"    Boolean bo = null;;\n" +
11724
				"	 bar(bo);\n" + // should warn
11725
				"  }\n" +
11726
				"  void bar(boolean b) {}\n" +
11727
				"}"},
11728
			"----------\n" + 
11729
			"1. ERROR in X.java (at line 4)\n" + 
11730
			"	bar(bo);\n" + 
11731
			"	    ^^\n" + 
11732
			"Null pointer access: The variable bo can only be null at this location\n" + 
11733
			"----------\n",
11734
		    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
11735
}
11736
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201
11737
// unboxing raises an NPE
11738
// Node types covered (in this order):
11739
//   ExplicitConstructorCall
11740
//   AllocationExpression
11741
//   AND_AND_Expression
11742
//   OR_OR_Expression
11743
//   ArrayAllocationExpression
11744
//   ForStatement
11745
//   DoStatement
11746
//   IfStatement
11747
//   QualifiedAllocationExpression
11748
//   SwitchStatement
11749
//   WhileStatement
11750
//   CastExpression
11751
//   AssertStatement
11752
//   ReturnStatement
11753
public void testBug319201c() {
11754
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
11755
		return;
11756
	runNegativeTest(
11757
			new String[] {
11758
              "X.java",
11759
              "class Y { public Y(boolean b1, boolean b2) {} }\n" +
11760
              "public class X extends Y {\n" +
11761
              "  public X(boolean b, Boolean b2) {\n" +
11762
              "      super(b2 == null, b2);\n" +
11763
              "  }\n" +
11764
              "  class Z {\n" +
11765
              "      public Z(boolean b) {}\n" +
11766
              "  }\n" +
11767
              "  boolean fB = (Boolean)null;\n" +
11768
              "  public boolean foo(boolean inB) {\n" +
11769
              "      Boolean b1 = null;\n" +
11770
              "      X x = new X(b1, null);\n" +
11771
              "      Boolean b2 = null;\n" +
11772
              "      boolean dontcare = b2 && inB;\n" +
11773
              "      Boolean b3 = null;\n" +
11774
              "      dontcare = inB || b3;\n" +
11775
              "      Integer dims = null;\n" +
11776
              "      char[] cs = new char[dims];\n" +
11777
              "      Boolean b5 = null;\n" +
11778
              "      do {\n" +
11779
              "          Boolean b4 = null;\n" +
11780
              "          for (int i=0;b4; i++);\n" +
11781
              "      } while (b5);\n" +
11782
              "      Boolean b6 = null;\n" +
11783
              "      if (b6) { }\n" +
11784
              "      Boolean b7 = null;\n" +
11785
              "      Z z = this.new Z(b7);\n" +
11786
              "      Integer sel = null;\n" +
11787
              "      switch(sel) {\n" +
11788
              "          case 1: break;\n" +
11789
              "          default: break;\n" +
11790
              "      }\n" +
11791
              "      Boolean b8 = null;\n" +
11792
              "      while (b8) {}\n" +
11793
              "      Boolean b9 = null;\n" +
11794
              "      dontcare = (boolean)b9;\n" +
11795
              "      Boolean b10 = null;\n" +
11796
              "      assert b10 : \"shouldn't happen, but will\";\n" +
11797
              "      Boolean b11 = null;\n" +
11798
              "      return b11;\n" +
11799
              "  }\n" +
11800
				"}"},
11801
			"----------\n" + 
11802
			"1. ERROR in X.java (at line 4)\n" + 
11803
			"	super(b2 == null, b2);\n" + 
11804
			"	                  ^^\n" + 
11805
			"Potential null pointer access: The variable b2 may be null at this location\n" + 
11806
			"----------\n" + 
11807
			"2. ERROR in X.java (at line 12)\n" + 
11808
			"	X x = new X(b1, null);\n" + 
11809
			"	            ^^\n" + 
11810
			"Null pointer access: The variable b1 can only be null at this location\n" + 
11811
			"----------\n" + 
11812
			"3. ERROR in X.java (at line 14)\n" + 
11813
			"	boolean dontcare = b2 && inB;\n" + 
11814
			"	                   ^^\n" + 
11815
			"Null pointer access: The variable b2 can only be null at this location\n" + 
11816
			"----------\n" + 
11817
			"4. ERROR in X.java (at line 16)\n" + 
11818
			"	dontcare = inB || b3;\n" + 
11819
			"	                  ^^\n" + 
11820
			"Null pointer access: The variable b3 can only be null at this location\n" + 
11821
			"----------\n" + 
11822
			"5. ERROR in X.java (at line 18)\n" + 
11823
			"	char[] cs = new char[dims];\n" + 
11824
			"	                     ^^^^\n" + 
11825
			"Null pointer access: The variable dims can only be null at this location\n" + 
11826
			"----------\n" + 
11827
			"6. ERROR in X.java (at line 22)\n" + 
11828
			"	for (int i=0;b4; i++);\n" + 
11829
			"	             ^^\n" + 
11830
			"Null pointer access: The variable b4 can only be null at this location\n" + 
11831
			"----------\n" + 
11832
			"7. ERROR in X.java (at line 23)\n" + 
11833
			"	} while (b5);\n" + 
11834
			"	         ^^\n" + 
11835
			"Null pointer access: The variable b5 can only be null at this location\n" + 
11836
			"----------\n" + 
11837
			"8. ERROR in X.java (at line 25)\n" + 
11838
			"	if (b6) { }\n" + 
11839
			"	    ^^\n" + 
11840
			"Null pointer access: The variable b6 can only be null at this location\n" + 
11841
			"----------\n" + 
11842
			"9. ERROR in X.java (at line 27)\n" + 
11843
			"	Z z = this.new Z(b7);\n" + 
11844
			"	                 ^^\n" + 
11845
			"Null pointer access: The variable b7 can only be null at this location\n" + 
11846
			"----------\n" + 
11847
			"10. ERROR in X.java (at line 29)\n" + 
11848
			"	switch(sel) {\n" + 
11849
			"	       ^^^\n" + 
11850
			"Null pointer access: The variable sel can only be null at this location\n" + 
11851
			"----------\n" + 
11852
			"11. ERROR in X.java (at line 34)\n" + 
11853
			"	while (b8) {}\n" + 
11854
			"	       ^^\n" + 
11855
			"Null pointer access: The variable b8 can only be null at this location\n" + 
11856
			"----------\n" + 
11857
			"12. ERROR in X.java (at line 36)\n" + 
11858
			"	dontcare = (boolean)b9;\n" + 
11859
			"	                    ^^\n" + 
11860
			"Null pointer access: The variable b9 can only be null at this location\n" + 
11861
			"----------\n" + 
11862
			"13. ERROR in X.java (at line 38)\n" + 
11863
			"	assert b10 : \"shouldn\'t happen, but will\";\n" + 
11864
			"	       ^^^\n" + 
11865
			"Null pointer access: The variable b10 can only be null at this location\n" + 
11866
			"----------\n" + 
11867
			"14. ERROR in X.java (at line 40)\n" + 
11868
			"	return b11;\n" + 
11869
			"	       ^^^\n" + 
11870
			"Null pointer access: The variable b11 can only be null at this location\n" + 
11871
			"----------\n",
11872
		    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
11873
}
11874
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201
11875
// unboxing raises an NPE
11876
// DoStatement, variants with assignement in the body & empty body
11877
public void testBug319201d() {
11878
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
11879
		return;
11880
	runNegativeTest(
11881
			new String[] {
11882
              "X.java",
11883
              "public class X {\n" +
11884
              "  public void foo(boolean cond, boolean cond2) {\n" +
11885
              "      Boolean b = null;\n" +
11886
              "      do {\n" +
11887
              "          b = false;\n" +
11888
              "          if (cond) continue;\n" +   // shouldn't make a difference
11889
              "      } while (b);\n" + // don't complain, loop body has already assigned b
11890
              "      Boolean b2 = null;\n" +
11891
              "      do {\n" +
11892
              "          if (cond) continue;\n" +
11893
              "          b2 = false;\n" +
11894
              "      } while (b2);\n" + // complain here: potentially null
11895
              "      Boolean b3 = null;\n" +
11896
              "      do {\n" +
11897
              "      } while (b3);\n" + // complain here: definitely null
11898
              "      Boolean b4 = null;\n" +
11899
              "      do {\n" +
11900
              "        if (cond) {\n" +
11901
              "            b4 = true;\n" +
11902
              "            if (cond2) continue;\n" +
11903
              "        }\n" +
11904
              "        b4 = false;\n" +
11905
              "      } while (b4);\n" + // don't complain here: definitely non-null
11906
              "  }\n" +
11907
			  "}"},
11908
			"----------\n" + 
11909
			"1. ERROR in X.java (at line 12)\n" + 
11910
			"	} while (b2);\n" + 
11911
			"	         ^^\n" + 
11912
			"Potential null pointer access: The variable b2 may be null at this location\n" + 
11913
			"----------\n" + 
11914
			"2. ERROR in X.java (at line 15)\n" + 
11915
			"	} while (b3);\n" + 
11916
			"	         ^^\n" + 
11917
			"Null pointer access: The variable b3 can only be null at this location\n" + 
11918
			"----------\n",
11919
		    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
11920
}
11665
}
11921
}

Return to bug 319201