diff options
author | Stephan Herrmann | 2018-02-22 20:28:43 +0000 |
---|---|---|
committer | Stephan Herrmann | 2018-02-22 20:53:23 +0000 |
commit | 62717d8fab80fa2f94b97912f8adf9f73499cf9a (patch) | |
tree | 95e8f65a3cb06aa841b053c4e6429e32b6fd7857 | |
parent | b6c75372c623d0fcdcf9f96460cccf69fb2cd407 (diff) | |
download | eclipse.jdt.core-62717d8fab80fa2f94b97912f8adf9f73499cf9a.tar.gz eclipse.jdt.core-62717d8fab80fa2f94b97912f8adf9f73499cf9a.tar.xz eclipse.jdt.core-62717d8fab80fa2f94b97912f8adf9f73499cf9a.zip |
Bug 433615 - [compiler][null] "Potential Null Pointer Access" shows as
error, instead of warning as specified in the Preferences
Change-Id: I0026030cbc994bd63306e030e4756d4e291014e9
3 files changed, 27 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java index 62bd142d3f..76cc4ee9f9 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java @@ -1788,7 +1788,7 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("NotVisibleField", SKIP); expectedProblemAttributes.put("NotVisibleMethod", SKIP); expectedProblemAttributes.put("NotVisibleType", SKIP); - expectedProblemAttributes.put("NullableFieldReference", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_REFERENCE)); + expectedProblemAttributes.put("NullableFieldReference", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE)); expectedProblemAttributes.put("NullAnnotationAtQualifyingType", SKIP); expectedProblemAttributes.put("NullAnnotationUnsupportedLocation", SKIP); expectedProblemAttributes.put("NullAnnotationUnsupportedLocationAtType", SKIP); 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 703c5baa88..84b07a0d5a 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2016 GK Software AG and others. + * Copyright (c) 2010, 2018 GK Software AG 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 @@ -5392,6 +5392,30 @@ public void test_nullable_field_16() { : "Null type mismatch (type annotations): required \'@NonNull Object\' but this expression has type \'@Nullable Object\'\n") + "----------\n"); } +// access to a nullable field - field reference +// Configured as of https://bugs.eclipse.org/bugs/show_bug.cgi?id=433615 +public void test_nullable_field_17() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.INFO); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o = new Object();\n" + + " public String oString() {\n" + + " return this.o.toString();\n" + + " }\n" + + "}\n" + }, + options /*customOptions*/, + "----------\n" + + "1. INFO in X.java (at line 5)\n" + + " return this.o.toString();\n" + + " ^\n" + + potNPE_nullable("The field o") + + "----------\n"); +} // an enum is declared within the scope of a null-default // https://bugs.eclipse.org/331649#c61 public void test_enum_field_01() { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java index 7db4a0943d..6fbe04433f 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java @@ -404,7 +404,6 @@ public static int getIrritant(int problemID) { return CompilerOptions.VarargsArgumentNeedCast; case IProblem.NullLocalVariableReference: - case IProblem.NullableFieldReference: case IProblem.NullExpressionReference: case IProblem.NullUnboxing: return CompilerOptions.NullReference; @@ -412,6 +411,7 @@ public static int getIrritant(int problemID) { case IProblem.PotentialNullLocalVariableReference: case IProblem.PotentialNullMessageSendReference: case IProblem.ArrayReferencePotentialNullReference: + case IProblem.NullableFieldReference: case IProblem.DereferencingNullableExpression: case IProblem.PotentialNullExpressionReference: case IProblem.PotentialNullUnboxing: |