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

Collapse All | Expand All

(-)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/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
	}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (+68 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
public void testBug319201() {
11668
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
11669
		return;
11670
	runNegativeTest(
11671
			new String[] {
11672
				"X.java",
11673
				"public class X {\n" +
11674
				"  public void foo() {\n" +
11675
				"	 Integer i = null;\n" +
11676
				"	 int j = i;\n" + // should warn
11677
				"  }\n" +
11678
				"}"},
11679
			"----------\n" + 
11680
			"1. ERROR in X.java (at line 4)\n" + 
11681
			"	int j = i;\n" + 
11682
			"	        ^\n" + 
11683
			"Null pointer access: The variable i can only be null at this location\n" + 
11684
			"----------\n",
11685
		    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
11686
}
11687
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201
11688
//unboxing could raise an NPE
11689
public void testBug319201a() {
11690
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
11691
		return;
11692
	runNegativeTest(
11693
			new String[] {
11694
				"X.java",
11695
				"public class X {\n" +
11696
				"  public void foo(Integer i) {\n" +
11697
				"    if (i == null) {};\n" +
11698
				"	 int j;\n" +
11699
				"	 j = i;\n" + // should warn
11700
				"  }\n" +
11701
				"}"},
11702
			"----------\n" + 
11703
			"1. ERROR in X.java (at line 5)\n" + 
11704
			"	j = i;\n" + 
11705
			"	    ^\n" + 
11706
			"Potential null pointer access: The variable i may be null at this location\n" + 
11707
			"----------\n",
11708
		    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
11709
}
11710
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201
11711
//unboxing raises an NPE
11712
public void testBug319201b() {
11713
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
11714
		return;
11715
	runNegativeTest(
11716
			new String[] {
11717
				"X.java",
11718
				"public class X {\n" +
11719
				"  public void foo() {\n" +
11720
				"    Boolean bo = null;;\n" +
11721
				"	 bar(bo);\n" + // should warn
11722
				"  }\n" +
11723
				"  void bar(boolean b) {}\n" +
11724
				"}"},
11725
			"----------\n" + 
11726
			"1. ERROR in X.java (at line 4)\n" + 
11727
			"	bar(bo);\n" + 
11728
			"	    ^^\n" + 
11729
			"Null pointer access: The variable bo can only be null at this location\n" + 
11730
			"----------\n",
11731
		    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
11732
}
11665
}
11733
}

Return to bug 319201