Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2013-01-17 20:21:30 +0000
committerJayaprakash Arthanareeswaran2013-02-05 19:19:19 +0000
commitaae374b319008b3e7997fb943d9dfc19fcb7029e (patch)
treea8243bf5a68be2ae46bd28a1cb600a16ea9a958a
parente49db6968e42abb8ff526d386a122936552a3efd (diff)
downloadeclipse.jdt.core-aae374b319008b3e7997fb943d9dfc19fcb7029e.tar.gz
eclipse.jdt.core-aae374b319008b3e7997fb943d9dfc19fcb7029e.tar.xz
eclipse.jdt.core-aae374b319008b3e7997fb943d9dfc19fcb7029e.zip
Bug 376263: Bogus "Potential null pointer access" warning
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java38
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java10
2 files changed, 46 insertions, 2 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 077a4468cd..c67196f8e5 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
@@ -24,6 +24,7 @@
* bug 367879 - Incorrect "Potential null pointer access" warning on statement after try-with-resources within try-finally
* bug 383690 - [compiler] location of error re uninitialized final field should be aligned
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
+ * bug 376263 - Bogus "Potential null pointer access" warning
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -32,6 +33,7 @@ import java.util.Map;
import junit.framework.Test;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.ToolFactory;
import org.eclipse.jdt.core.tests.util.Util;
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
@@ -53,6 +55,7 @@ public NullReferenceTest(String name) {
static {
// TESTS_NAMES = new String[] { "testBug345305_14" };
// TESTS_NAMES = new String[] { "test0515_try_finally" };
+// TESTS_NAMES = new String[] { "testBug376263" };
// TESTS_NUMBERS = new int[] { 561 };
// TESTS_RANGE = new int[] { 1, 2049 };
}
@@ -15623,6 +15626,41 @@ public void testBug360328d() {
"",/* expected error */
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
+public void testBug376263() {
+ Map customOptions = getCompilerOptions();
+ customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR);
+ runConformTest(
+ new String[] {
+ "Test.java",
+ "public class Test {\n" +
+ " private int x;\n" +
+ "\n" +
+ " static void test(Test[] array) {\n" +
+ " Test elem = null;\n" +
+ " int i = 0;\n" +
+ " while (i < array.length) {\n" +
+ " if (i == 0) {\n" +
+ " elem = array[0];\n" +
+ " }\n" +
+ " if (elem != null) {\n" +
+ " while (true) {\n" +
+ " if (elem.x >= 0 || i >= array.length) { // should not warn here\n" +
+ " break;\n" +
+ " }\n" +
+ " elem = array[i++];\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}"
+ },
+ "",
+ null/*classLibraries*/,
+ true/*shouldFlush*/,
+ null/*vmArgs*/,
+ customOptions,
+ null/*requestor*/);
+}
// Bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
// simplified: only try-finally involved
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 5020e8aea0..5dcf13ac5e 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
@@ -15,6 +15,7 @@
* bug 365859 - [compiler][null] distinguish warnings based on flow analysis vs. null annotations
* bug 385626 - @NonNull fails across loop boundaries
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
+ * bug 376263 - Bogus "Potential null pointer access" warning
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.flow;
@@ -148,6 +149,7 @@ public void complainOnDeferredNullChecks(BlockScope scope, FlowInfo callerFlowIn
addPotentialNullInfoFrom(this.innerFlowInfos[i]);
}
this.innerFlowContextsCount = 0;
+ FlowInfo upstreamCopy = this.upstreamNullFlowInfo.copy();
UnconditionalFlowInfo flowInfo = this.upstreamNullFlowInfo.
addPotentialNullInfoFrom(callerFlowInfo.unconditionalInitsWithoutSideEffect());
if ((this.tagBits & FlowContext.DEFER_NULL_DIAGNOSTIC) != 0) {
@@ -277,8 +279,12 @@ public void complainOnDeferredNullChecks(BlockScope scope, FlowInfo callerFlowIn
default:
// never happens
}
- this.parent.recordUsingNullReference(scope, local, location,
- this.nullCheckTypes[i], flowInfo);
+ // https://bugs.eclipse.org/376263: avoid further deferring if the upstream info
+ // already has definite information (which might get lost for deferred checking).
+ if (!(this.nullCheckTypes[i] == MAY_NULL && upstreamCopy.isDefinitelyNonNull(local))) {
+ this.parent.recordUsingNullReference(scope, local, location,
+ this.nullCheckTypes[i], flowInfo);
+ }
}
}
else {

Back to the top