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

Return to bug 319201