Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2017-04-13 22:15:50 +0000
committerStephan Herrmann2017-04-13 22:15:50 +0000
commit4338868bca17d013740bdd5f87257ce2620da83a (patch)
tree22a1128ea641c7f13a330379fd10de7b76e7d221 /org.eclipse.jdt.core.tests.compiler/src
parentcb0a7308a9e951a76867f8a7170d00b125238fe5 (diff)
downloadeclipse.jdt.core-4338868bca17d013740bdd5f87257ce2620da83a.tar.gz
eclipse.jdt.core-4338868bca17d013740bdd5f87257ce2620da83a.tar.xz
eclipse.jdt.core-4338868bca17d013740bdd5f87257ce2620da83a.zip
Bug 414761: [null] Annotation-based nullnes inference fails for fields
in 'while' loop Change-Id: I313719ad6739e1dbc745d8870c2a0955a4e320e3 Signed-off-by: Stephan Herrmann <stephan.herrmann@berlin.de>
Diffstat (limited to 'org.eclipse.jdt.core.tests.compiler/src')
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java47
1 files changed, 47 insertions, 0 deletions
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 eee31ad799..96bbce47e1 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
@@ -5372,6 +5372,53 @@ public void test_nullable_field_15() {
potNPE_nullable("The field nullable") +
"----------\n");
}
+// access to a nullable field - dereference after check in while loop
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=414761
+public void test_nullable_field_16() {
+ // currently no flow analysis for fields is implemented,
+ // but the direct sequence of null-check + dereference is optionally supported as a special case
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED);
+ runNegativeTestWithLibs(
+ new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " @Nullable Object prop;\n" +
+ " void testWhileAlone(){\n" +
+ " while(this.prop != null) {\n" +
+ " test(this.prop);\n" +
+ " }\n" +
+ " }\n" +
+ " @Nullable Object other;\n" +
+ " void testTwoFields() {\n" +
+ " boolean b = this.other != null;\n" + // we had funny interaction between analyses of other & prop
+ " while(this.prop != null) {\n" +
+ " test(this.prop);\n" +
+ " }\n" +
+ " }\n" +
+ " void testWhileInIf() {\n" +
+ " if (this.prop != null) {\n" +
+ " while(this.other != null) {\n" +
+ " test(this.prop);\n" + // no longer protected by outer if
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " void test(@NonNull Object param){\n" +
+ " assert param != null;\n" +
+ " }" +
+ "}\n"
+ },
+ options /*customOptions*/,
+ "----------\n" +
+ "1. ERROR in X.java (at line 19)\n" +
+ " test(this.prop);\n" +
+ " ^^^^^^^^^\n" +
+ (this.complianceLevel < ClassFileConstants.JDK1_8
+ ? "Null type mismatch: required '@NonNull Object' but the provided value is specified as @Nullable\n"
+ : "Null type mismatch (type annotations): required \'@NonNull Object\' but this expression has type \'@Nullable Object\'\n") +
+ "----------\n");
+}
// an enum is declared within the scope of a null-default
// https://bugs.eclipse.org/331649#c61
public void test_enum_field_01() {

Back to the top