Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2013-04-18 23:14:12 +0000
committerJayaprakash Arthanareeswaran2013-05-16 10:59:04 +0000
commit04ba8714847b0b2ff7093c5cc3d0c90b552f67e9 (patch)
tree79156dd6a849f80854edb3396f6755fe50027465
parent650909e8cb3636454033b091607121770e4ba739 (diff)
downloadeclipse.jdt.core-04ba8714847b0b2ff7093c5cc3d0c90b552f67e9.tar.gz
eclipse.jdt.core-04ba8714847b0b2ff7093c5cc3d0c90b552f67e9.tar.xz
eclipse.jdt.core-04ba8714847b0b2ff7093c5cc3d0c90b552f67e9.zip
Bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction
between unboxing, NPE, and deferred checking - uniform checking for all relevant AST nodes
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java36
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java9
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java7
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayReference.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java7
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.java7
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java7
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java11
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java7
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java10
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java10
19 files changed, 91 insertions, 64 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
index 606345de5e..138b822d59 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
@@ -1225,6 +1225,42 @@ public void test0037_autounboxing_4() {
"}\n"},
options);
}
+// https://bugs.eclipse.org/403147 [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
+// array reference in nested try
+public void test0037_autounboxing_5() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return;
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR);
+ runNegativeTest(
+ true,
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void foo(Object [] o, boolean b, Integer i) {\n" +
+ " int j = 1;\n" +
+ " try {\n" +
+ " if (b) i = null;\n" +
+ " } catch (RuntimeException r) {\n" +
+ " i = 3;\n" +
+ " } finally {\n" +
+ " try {\n" +
+ " System.out.println(o[i]); \n" +
+ " } finally {\n" +
+ " System.out.println(j);\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"},
+ null,
+ options,
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " System.out.println(o[i]); \n" +
+ " ^\n" +
+ "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+}
// null analysis -- autoboxing
public void test0040_autoboxing_compound_assignment() {
if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java
index 8ae057c527..6d109319cb 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java
@@ -10,6 +10,7 @@
* Stephan Herrmann - Contributions for
* bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE
* bug 403086 - [compiler][null] include the effect of 'assert' in syntactic null analysis for fields
+ * bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -67,12 +68,8 @@ public class AND_AND_Expression extends BinaryExpression {
rightInfo = this.right.analyseCode(currentScope, flowContext, rightInfo);
if ((flowContext.tagBits & FlowContext.INSIDE_NEGATION) != 0)
flowContext.expireNullCheckedFieldInfo();
- if ((this.left.implicitConversion & TypeIds.UNBOXING) != 0) {
- this.left.checkNPE(currentScope, flowContext, flowInfo);
- }
- if ((this.right.implicitConversion & TypeIds.UNBOXING) != 0) {
- this.right.checkNPE(currentScope, flowContext, flowInfo);
- }
+ this.left.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
+ this.right.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
FlowInfo mergedInfo = FlowInfo.conditional(
rightInfo.safeInitsWhenTrue(),
leftInfo.initsWhenFalse().unconditionalInits().mergedWith(
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java
index f05f3ea8ac..2067bb6213 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java
@@ -21,6 +21,7 @@
* bug 370639 - [compiler][resource] restore the default for resource leak warnings
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
* bug 388996 - [compiler][resource] Incorrect 'potential resource leak'
+ * bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
* Jesper S Moller <jesper@selskabet.org> - Contributions for
* bug 378674 - "The method can be declared as static" is wrong
* Andy Clement - Contributions for
@@ -72,9 +73,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
if (analyseResources && !hasResourceWrapperType) { // allocation of wrapped closeables is analyzed specially
flowInfo = FakedTrackingVariable.markPassedToOutside(currentScope, this.arguments[i], flowInfo, flowContext, false);
}
- if ((this.arguments[i].implicitConversion & TypeIds.UNBOXING) != 0) {
- this.arguments[i].checkNPE(currentScope, flowContext, flowInfo);
- }
+ this.arguments[i].checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
}
analyseArguments(currentScope, flowContext, flowInfo, this.binding, this.arguments);
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java
index 2022890c39..9bb15e8747 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,6 +14,7 @@
* Stephan Herrmann - Contributions for
* bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
+ * bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -38,9 +39,7 @@ public class ArrayAllocationExpression extends Expression {
Expression dim;
if ((dim = this.dimensions[i]) != null) {
flowInfo = dim.analyseCode(currentScope, flowContext, flowInfo);
- if ((dim.implicitConversion & TypeIds.UNBOXING) != 0) {
- dim.checkNPE(currentScope, flowContext, flowInfo);
- }
+ dim.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
}
}
// account for potential OutOfMemoryError:
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayReference.java
index 1f5c4d27d9..4c896b1add 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -15,6 +15,7 @@
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
* bug 392862 - [1.8][compiler][null] Evaluate null annotations on array types
* bug 383368 - [compiler][null] syntactic null analysis for field references
+ * bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -66,6 +67,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
this.receiver.checkNPE(currentScope, flowContext, flowInfo);
flowInfo = this.receiver.analyseCode(currentScope, flowContext, flowInfo);
flowInfo = this.position.analyseCode(currentScope, flowContext, flowInfo);
+ this.position.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
// account for potential ArrayIndexOutOfBoundsException:
flowContext.recordAbruptExit();
return flowInfo;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java
index 7cc168bb54..17cbc01f38 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java
@@ -11,6 +11,7 @@
* bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
* bug 403086 - [compiler][null] include the effect of 'assert' in syntactic null analysis for fields
+ * bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -47,9 +48,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
this.preAssertInitStateIndex = currentScope.methodScope().recordInitializationStates(flowInfo);
Constant cst = this.assertExpression.optimizedBooleanConstant();
- if ((this.assertExpression.implicitConversion & TypeIds.UNBOXING) != 0) {
- this.assertExpression.checkNPE(currentScope, flowContext, flowInfo);
- }
+ this.assertExpression.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
boolean isOptimizedTrueAssertion = cst != Constant.NotAConstant && cst.booleanValue() == true;
boolean isOptimizedFalseAssertion = cst != Constant.NotAConstant && cst.booleanValue() == false;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java
index f2199f892a..6385def68d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java
@@ -28,6 +28,7 @@
* bug 331649 - [compiler][null] consider null annotations for fields
* bug 383368 - [compiler][null] syntactic null analysis for field references
* bug 402993 - [null] Follow up of bug 401088: Missing warning about redundant null check
+ * bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -59,9 +60,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
// a field reference, a blank final field reference, a field of an enclosing instance or
// just a local variable.
LocalVariableBinding local = this.lhs.localVariableBinding();
- if ((this.expression.implicitConversion & TypeIds.UNBOXING) != 0) {
- this.expression.checkNPE(currentScope, flowContext, flowInfo);
- }
+ this.expression.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
FlowInfo preInitInfo = null;
CompilerOptions compilerOptions = currentScope.compilerOptions();
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java
index 6a76c3e8fd..267ba15f58 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,6 +10,7 @@
* Stephan Herrmann - Contributions for
* bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
+ * bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -83,9 +84,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
actionInfo.mergedWith(loopingContext.initsOnContinue));
}
}
- if ((this.condition.implicitConversion & TypeIds.UNBOXING) != 0) {
- this.condition.checkNPE(currentScope, flowContext, initsOnCondition);
- }
+ this.condition.checkNPEbyUnboxing(currentScope, flowContext, initsOnCondition);
/* Reset reach mode, to address following scenario.
* final blank;
* do { if (true) break; else blank = 0; } while(false);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java
index f6202d5cba..89b0e42a54 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java
@@ -17,6 +17,7 @@
* bug 361407 - Resource leak warning when resource is assigned to a field outside of constructor
* bug 370639 - [compiler][resource] restore the default for resource leak warnings
* bug 388996 - [compiler][resource] Incorrect 'potential resource leak'
+ * bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -91,9 +92,7 @@ public class ExplicitConstructorCall extends Statement implements InvocationSite
// if argument is an AutoCloseable insert info that it *may* be closed (by the target constructor, i.e.)
flowInfo = FakedTrackingVariable.markPassedToOutside(currentScope, this.arguments[i], flowInfo, flowContext, false);
}
- if ((this.arguments[i].implicitConversion & TypeIds.UNBOXING) != 0) {
- this.arguments[i].checkNPE(currentScope, flowContext, flowInfo);
- }
+ this.arguments[i].checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
}
analyseArguments(currentScope, flowContext, flowInfo, this.binding, this.arguments);
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java
index c5437e8cb9..8b6189a9ea 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java
@@ -591,11 +591,12 @@ public boolean checkNPE(BlockScope scope, FlowContext flowContext, FlowInfo flow
/** If this expression requires unboxing check if that operation can throw NPE. */
protected void checkNPEbyUnboxing(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo) {
+ int status;
if ((this.implicitConversion & UNBOXING) != 0
&& (this.bits & ASTNode.IsNonNull) == 0
- && nullStatus(flowInfo, flowContext) != FlowInfo.NON_NULL)
+ && (status = nullStatus(flowInfo, flowContext)) != FlowInfo.NON_NULL)
{
- flowContext.recordUnboxing(scope, this, flowInfo);
+ flowContext.recordUnboxing(scope, this, status, flowInfo);
}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.java
index 88948bb859..37dac8e786 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,7 @@
* bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE
* bug 349326 - [1.7] new warning for missing try-with-resources
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
+ * bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -96,9 +97,7 @@ public class ForStatement extends Statement {
new LoopingFlowContext(flowContext, flowInfo, this, null,
null, this.scope, true)),
condInfo);
- if ((this.condition.implicitConversion & TypeIds.UNBOXING) != 0) {
- this.condition.checkNPE(currentScope, flowContext, flowInfo);
- }
+ this.condition.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java
index 0521cb41c3..254ff71def 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,6 +12,7 @@
* bug 349326 - [1.7] new warning for missing try-with-resources
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
* bug 383368 - [compiler][null] syntactic null analysis for field references
+ * bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -62,9 +63,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
int initialComplaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED;
Constant cst = this.condition.optimizedBooleanConstant();
- if ((this.condition.implicitConversion & TypeIds.UNBOXING) != 0) {
- this.condition.checkNPE(currentScope, flowContext, flowInfo);
- }
+ this.condition.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
boolean isConditionOptimizedTrue = cst != Constant.NotAConstant && cst.booleanValue() == true;
boolean isConditionOptimizedFalse = cst != Constant.NotAConstant && cst.booleanValue() == false;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java
index 9825fb7bf5..b379cf51ed 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java
@@ -32,6 +32,7 @@
* bug 382350 - [1.8][compiler] Unable to invoke inherited default method via I.super.m() syntax
* bug 404649 - [1.8][compiler] detect illegal reference to indirect or redundant super
* bug 403086 - [compiler][null] include the effect of 'assert' in syntactic null analysis for fields
+ * bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
* Jesper S Moller - Contributions for
* Bug 378674 - "The method can be declared as static" is wrong
* Andy Clement - Contributions for
@@ -137,9 +138,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
int length = this.arguments.length;
for (int i = 0; i < length; i++) {
Expression argument = this.arguments[i];
- if ((argument.implicitConversion & TypeIds.UNBOXING) != 0) {
- argument.checkNPE(currentScope, flowContext, flowInfo);
- }
+ argument.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
switch (detectAssertionUtility(i)) {
case TRUE_ASSERTION:
flowInfo = analyseBooleanAssertion(currentScope, argument, flowContext, flowInfo, wasInsideAssert, true);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java
index 4d05409f31..5e81242910 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,7 @@
* bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE
* bug 383368 - [compiler][null] syntactic null analysis for field references
* bug 403086 - [compiler][null] include the effect of 'assert' in syntactic null analysis for fields
+ * bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -72,12 +73,8 @@ public class OR_OR_Expression extends BinaryExpression {
rightInfo = this.right.analyseCode(currentScope, flowContext, rightInfo);
if ((flowContext.tagBits & FlowContext.INSIDE_NEGATION) == 0)
flowContext.expireNullCheckedFieldInfo();
- if ((this.left.implicitConversion & TypeIds.UNBOXING) != 0) {
- this.left.checkNPE(currentScope, flowContext, flowInfo);
- }
- if ((this.right.implicitConversion & TypeIds.UNBOXING) != 0) {
- this.right.checkNPE(currentScope, flowContext, flowInfo);
- }
+ this.left.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
+ this.right.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
// The definitely null variables in right info when true should not be missed out while merging
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=299900
FlowInfo leftInfoWhenTrueForMerging = leftInfo.initsWhenTrue().unconditionalCopy().addPotentialInitializationsFrom(rightInfo.unconditionalInitsWithoutSideEffect());
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
index 4c80495ac9..ec3a54fbd8 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
@@ -20,6 +20,7 @@
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
* bug 388996 - [compiler][resource] Incorrect 'potential resource leak'
* bug 395977 - [compiler][resource] Resource leak warning behavior possibly incorrect for anonymous inner class
+ * bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
* Jesper S Moller <jesper@selskabet.org> - Contributions for
* bug 378674 - "The method can be declared as static" is wrong
* Andy Clement - Contributions for
@@ -108,9 +109,7 @@ public class QualifiedAllocationExpression extends AllocationExpression {
// if argument is an AutoCloseable insert info that it *may* be closed (by the target method, i.e.)
flowInfo = FakedTrackingVariable.markPassedToOutside(currentScope, this.arguments[i], flowInfo, flowContext, false);
}
- if ((this.arguments[i].implicitConversion & TypeIds.UNBOXING) != 0) {
- this.arguments[i].checkNPE(currentScope, flowContext, flowInfo);
- }
+ this.arguments[i].checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
}
analyseArguments(currentScope, flowContext, flowInfo, this.binding, this.arguments);
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java
index 54b3a16fc9..837f432e9d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,7 @@
* bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE
* bug 349326 - [1.7] new warning for missing try-with-resources
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
+ * bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -67,9 +68,7 @@ public class WhileStatement extends Statement {
new LoopingFlowContext(flowContext, flowInfo, this, null,
null, currentScope, true)),
condInfo);
- if ((this.condition.implicitConversion & TypeIds.UNBOXING) != 0) {
- this.condition.checkNPE(currentScope, flowContext, flowInfo);
- }
+ this.condition.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
LoopingFlowContext loopingContext;
FlowInfo actionInfo;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java
index 03c113d076..d9188794e3 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -455,9 +455,11 @@ protected void recordNullReference(LocalVariableBinding local,
this.nullReferences[this.nullCount] = expression;
this.nullCheckTypes[this.nullCount++] = checkType;
}
-public void recordUnboxing(Scope scope, Expression expression, FlowInfo flowInfo) {
- // defer checking:
- recordNullReference(null, expression, IN_UNBOXING);
+public void recordUnboxing(Scope scope, Expression expression, int nullStatus, FlowInfo flowInfo) {
+ if (nullStatus == FlowInfo.NULL)
+ super.recordUnboxing(scope, expression, nullStatus, flowInfo);
+ else // defer checking:
+ recordNullReference(null, expression, IN_UNBOXING);
}
protected boolean internalRecordNullityMismatch(Expression expression, TypeBinding providedType, int nullStatus, TypeBinding expectedType, int checkType) {
// cf. decision structure inside FinallyFlowContext.recordUsingNullReference(..)
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java
index a737f3b655..4804eecaec 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java
@@ -774,8 +774,9 @@ protected void recordNullReference(LocalVariableBinding local,
/**
* Either AST analysis or checking of a child flow context has encountered an unboxing situation.
* Record this fact for handling at an appropriate point in time.
+ * @param nullStatus the status as we know it so far.
*/
-public void recordUnboxing(Scope scope, Expression expression, FlowInfo flowInfo) {
+public void recordUnboxing(Scope scope, Expression expression, int nullStatus, FlowInfo flowInfo) {
// default: handle immediately:
checkUnboxing(scope, expression, flowInfo);
}
@@ -793,7 +794,7 @@ protected void checkUnboxing(Scope scope, Expression expression, FlowInfo flowIn
}
// not handled, perhaps our parent will eventually have something to say?
if (this.parent != null) {
- this.parent.recordUnboxing(scope, expression, flowInfo);
+ this.parent.recordUnboxing(scope, expression, FlowInfo.UNKNOWN, flowInfo);
}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java
index 68eb6c8e1d..53f9c0afae 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -543,9 +543,11 @@ protected void recordNullReference(LocalVariableBinding local,
this.nullReferences[this.nullCount] = expression;
this.nullCheckTypes[this.nullCount++] = checkType;
}
-public void recordUnboxing(Scope scope, Expression expression, FlowInfo flowInfo) {
- // defer checking:
- recordNullReference(null, expression, IN_UNBOXING);
+public void recordUnboxing(Scope scope, Expression expression, int nullStatus, FlowInfo flowInfo) {
+ if (nullStatus == FlowInfo.NULL)
+ super.recordUnboxing(scope, expression, nullStatus, flowInfo);
+ else // defer checking:
+ recordNullReference(null, expression, IN_UNBOXING);
}
/** Record the fact that we see an early exit (in 'reference') while 'trackingVar' is in scope and may be unclosed. */

Back to the top