diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java index 907ac4e..adff41e 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java @@ -52,7 +52,7 @@ // Static initializer to specify tests subset using TESTS_* static variables // All specified tests which do not belong to the class are skipped... static { -// TESTS_NAMES = new String[] { "test_illegal_annotation_007" }; +// TESTS_NAMES = new String[] { "test_assignment_expression_1" }; // TESTS_NUMBERS = new int[] { 561 }; // TESTS_RANGE = new int[] { 1, 2049 }; } @@ -2474,6 +2474,36 @@ "Type mismatch: required \'@NonNull String\' but the provided value can be null\n" + "----------\n"); } +public void test_assignment_expression_1() { + Map customOptions = getCompilerOptions(); +// customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR); + customOptions.put(JavaCore.COMPILER_NONNULL_IS_DEFAULT, JavaCore.ENABLED); + customOptions.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object foo() {\n" + + " Object o = null;\n" + + " boolean keepLooking = true;\n" + + " while(keepLooking) {\n" + + " if ((o=getO()) != null) {\n" + + " return o;\n" + + " }\n" + + " }\n" + + " return null;\n" + + " }\n" + + "\n" + + " private @Nullable Object getO() {\n" + + " return new Object();\n" + + " }\n" + + "}\n", + + }, + customOptions, + ""); +} // a nonnull variable is dereferenced method of a nested type public void test_nesting_1() { Map customOptions = getCompilerOptions(); 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 1d8c153..3eda768 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 @@ -119,7 +119,7 @@ } public void checkNPE(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo) { super.checkNPE(scope, flowContext, flowInfo); - if (nullStatus(flowInfo) == FlowInfo.POTENTIALLY_NULL) + if ((nullStatus(flowInfo) & FlowInfo.POTENTIALLY_NULL) != 0) scope.problemReporter().messageSendPotentialNullReference(this.binding, this); } /** @@ -281,7 +281,7 @@ if ((tagBits & TagBits.AnnotationNonNull) != 0) return FlowInfo.NON_NULL; if ((tagBits & TagBits.AnnotationNullable) != 0) - return FlowInfo.POTENTIALLY_NULL; + return FlowInfo.POTENTIALLY_NULL | FlowInfo.POTENTIALLY_NON_NULL; } return FlowInfo.UNKNOWN; }