Bug 465085 - [null] False positive potential null warning/error when
using isInstance()
Change-Id: Ica0b19897bd64b4686658f297aefc2f00b2bec91
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullChecksTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullChecksTests.java
index 353a2b3..6d8dfda 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullChecksTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullChecksTests.java
@@ -16,6 +16,7 @@
import java.util.Map;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import junit.framework.Test;
@@ -421,4 +422,26 @@
"Null pointer access: The variable initiallyNN can only be null at this location\n" +
"----------\n");
}
+ public void testBug465085_comment12() {
+ Map<String, String> options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR);
+ runConformTest(
+ new String[] {
+ "Snippet.java",
+ "import java.util.Collection;\n" +
+ "\n" +
+ "public class Snippet {\n" +
+ " int instanceCount(Collection<?> elements, Class<?> clazz) {\n" +
+ " int count = 0;\n" +
+ " for (Object o : elements) { // warning here: \"The value of the local variable o is not used\"\n" +
+ " if (clazz.isInstance(o)) {\n" +
+ " count++;\n" +
+ " }\n" +
+ " }\n" +
+ " return count;\n" +
+ " }\n" +
+ "}\n"
+ },
+ options);
+ }
}
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 06346e6..7f7d96a 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
@@ -222,12 +222,15 @@
break;
case ARG_NONNULL_IF_TRUE:
recordFlowUpdateOnResult(((SingleNameReference) argument).localVariableBinding(), true, false);
+ flowInfo = argument.analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
break;
case ARG_NONNULL_IF_TRUE_NEGATABLE:
recordFlowUpdateOnResult(((SingleNameReference) argument).localVariableBinding(), true, true);
+ flowInfo = argument.analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
break;
case ARG_NULL_IF_TRUE:
recordFlowUpdateOnResult(((SingleNameReference) argument).localVariableBinding(), false, true);
+ flowInfo = argument.analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
break;
default:
flowInfo = argument.analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();