diff options
author | Stephan Herrmann | 2019-09-12 13:23:29 +0000 |
---|---|---|
committer | Stephan Herrmann | 2019-09-12 16:59:23 +0000 |
commit | efc2bcb5776a5751c606265c2975560201e091d1 (patch) | |
tree | 3e8c44b413ce9af26594fa9c94c0d33035740c35 | |
parent | 328421a0239051bed525c280adc9937c7a561a78 (diff) | |
download | eclipse.jdt.core-efc2bcb5776a5751c606265c2975560201e091d1.tar.gz eclipse.jdt.core-efc2bcb5776a5751c606265c2975560201e091d1.tar.xz eclipse.jdt.core-efc2bcb5776a5751c606265c2975560201e091d1.zip |
Bug 551012 - New problems with Redundant null check for involving
constants
Change-Id: I2f369a02faf7a702532c35458f7f182fc6abad39
9 files changed, 64 insertions, 7 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF b/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF index 04a0637263..06473e3aaf 100644 --- a/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jdt.core.tests.compiler;singleton:=true -Bundle-Version: 3.12.950.qualifier +Bundle-Version: 3.12.1000.qualifier Bundle-Vendor: %providerName Bundle-Localization: plugin Export-Package: org.eclipse.jdt.core.tests.compiler, diff --git a/org.eclipse.jdt.core.tests.compiler/pom.xml b/org.eclipse.jdt.core.tests.compiler/pom.xml index 90188af22c..71cb2981a5 100644 --- a/org.eclipse.jdt.core.tests.compiler/pom.xml +++ b/org.eclipse.jdt.core.tests.compiler/pom.xml @@ -20,7 +20,7 @@ </parent> <groupId>org.eclipse.jdt</groupId> <artifactId>org.eclipse.jdt.core.tests.compiler</artifactId> - <version>3.12.950-SNAPSHOT</version> + <version>3.12.1000-SNAPSHOT</version> <packaging>eclipse-test-plugin</packaging> <properties> 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 29c8fd609b..5283c50b11 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 @@ -412,6 +412,7 @@ public void test011_problem_categories() { expectedProblemAttributes.put("CodeCannotBeReached", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("CodeSnippetMissingClass", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("CodeSnippetMissingMethod", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("ConstNonNullFieldComparisonYieldsFalse", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); expectedProblemAttributes.put("ContainerAnnotationTypeHasNonDefaultMembers", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("ContainerAnnotationTypeHasShorterRetention", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("ContainerAnnotationTypeHasWrongValueType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); @@ -1362,6 +1363,7 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("CodeSnippetMissingClass", SKIP); expectedProblemAttributes.put("CodeSnippetMissingMethod", SKIP); expectedProblemAttributes.put("ComparingIdentical", new ProblemAttributes(JavaCore.COMPILER_PB_COMPARING_IDENTICAL)); + expectedProblemAttributes.put("ConstNonNullFieldComparisonYieldsFalse", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); expectedProblemAttributes.put("ConflictingImport", SKIP); expectedProblemAttributes.put("ConflictingNullAnnotations", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); expectedProblemAttributes.put("ConstructedArrayIncompatible", SKIP); 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 20134ad43b..2d3bd0c032 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 @@ -17457,7 +17457,7 @@ public void testBug435528_orig() { "1. ERROR in Test.java (at line 10)\n" + " if (a != null) {\n" + " ^\n" + - "Null comparison always yields false: The field a is a nonnull constant\n" + + "Redundant null check: The field a is a nonnull constant\n" + "----------\n" + "2. WARNING in Test.java (at line 15)\n" + " } else {\n" + @@ -18332,4 +18332,55 @@ public void testBug544872() { "----------\n" ); } +public void testBug551012() { + runNegativeTest( + new String[] { + "NullConstants.java", + "public class NullConstants {\n" + + " protected static final String FOO = null;\n" + + "\n" + + " protected String foo = FOO;\n" + + "\n" + + " protected static final String BAR = \"\";\n" + + "\n" + + " protected String bar = BAR;\n" + + "\n" + + " public boolean notAProblemButWhyNot() {\n" + + " return FOO == null ? foo != null : !FOO.equals(foo);\n" + + " }\n" + + "\n" + + " public boolean alsoNotAProblemButThisWillAlwaysNPE() {\n" + + " return FOO != null ? foo != null : !FOO.equals(foo);\n" + + " }\n" + + "\n" + + " public boolean aProblemButHowToAvoid() {\n" + + " return BAR == null ? bar != null : !BAR.equals(bar);\n" + + " }\n" + + "\n" + + " public boolean wrongpProblemMessage() {\n" + + " return BAR != null ? !BAR.equals(bar) : bar != null;\n" + + " }\n" + + "\n" + + " public boolean howAboutThis() {\n" + + " return bar == null ? BAR != null : bar.equals(BAR);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in NullConstants.java (at line 19)\n" + + " return BAR == null ? bar != null : !BAR.equals(bar);\n" + + " ^^^\n" + + "Null comparison always yields false: The field BAR is a nonnull constant\n" + + "----------\n" + + "2. ERROR in NullConstants.java (at line 23)\n" + + " return BAR != null ? !BAR.equals(bar) : bar != null;\n" + + " ^^^\n" + + "Redundant null check: The field BAR is a nonnull constant\n" + + "----------\n" + + "3. ERROR in NullConstants.java (at line 27)\n" + + " return bar == null ? BAR != null : bar.equals(BAR);\n" + + " ^^^\n" + + "Redundant null check: The field BAR is a nonnull constant\n" + + "----------\n"); +} }
\ No newline at end of file diff --git a/org.eclipse.jdt.core/META-INF/MANIFEST.MF b/org.eclipse.jdt.core/META-INF/MANIFEST.MF index 2c6626061d..0344c1346a 100644 --- a/org.eclipse.jdt.core/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.core/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Main-Class: org.eclipse.jdt.internal.compiler.batch.Main Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jdt.core; singleton:=true -Bundle-Version: 3.19.100.qualifier +Bundle-Version: 3.20.0.qualifier Bundle-Activator: org.eclipse.jdt.core.JavaCore Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java index 15f4535a74..d253f404a8 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java @@ -1804,6 +1804,8 @@ void setSourceStart(int sourceStart); int RedundantNullDefaultAnnotationModule = Internal + 943; /** @since 3.19 */ int RedundantNullCheckOnConstNonNullField = Internal + 944; + /** @since 3.20 */ + int ConstNonNullFieldComparisonYieldsFalse = Internal + 945; /** @since 3.10 */ int ArrayReferencePotentialNullReference = Internal + 951; 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 6d95c7fc94..50ebb1c56d 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 @@ -436,6 +436,7 @@ public static int getIrritant(int problemID) { case IProblem.RedundantNullCheckAgainstNonNullType: case IProblem.RedundantNullCheckOnField: case IProblem.RedundantNullCheckOnConstNonNullField: + case IProblem.ConstNonNullFieldComparisonYieldsFalse: case IProblem.FieldComparisonYieldsFalse: return CompilerOptions.RedundantNullCheck; @@ -6058,7 +6059,7 @@ public boolean expressionNonNullComparison(Expression expr, boolean checkForNull arguments = new String[] { new String(field.name), new String(nonNullName[nonNullName.length-1]) }; } else if (field.constant() != Constant.NotAConstant) { - problemId = IProblem.RedundantNullCheckOnConstNonNullField; + problemId = checkForNull ? IProblem.ConstNonNullFieldComparisonYieldsFalse : IProblem.RedundantNullCheckOnConstNonNullField; char[][] nonNullName = this.options.nonNullAnnotationName; arguments = new String[] { new String(field.name), new String(nonNullName[nonNullName.length-1]) }; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties index 33ac72c329..27b62609e6 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties @@ -815,7 +815,8 @@ 941 = Redundant null check: The field {0} cannot be null at this location (ignoring concurrency) 942 = Null comparison always yields false: The field {0} cannot be null at this location (ignoring concurrency) 943 = Nullness default is redundant with a default specified for the enclosing module {0} -944 = Null comparison always yields false: The field {0} is a nonnull constant +944 = Redundant null check: The field {0} is a nonnull constant +945 = Null comparison always yields false: The field {0} is a nonnull constant 951 = Potential null pointer access: array element may be null diff --git a/org.eclipse.jdt.core/pom.xml b/org.eclipse.jdt.core/pom.xml index ff4c56c977..c2ce2e61d9 100644 --- a/org.eclipse.jdt.core/pom.xml +++ b/org.eclipse.jdt.core/pom.xml @@ -18,7 +18,7 @@ </parent> <groupId>org.eclipse.jdt</groupId> <artifactId>org.eclipse.jdt.core</artifactId> - <version>3.19.100-SNAPSHOT</version> + <version>3.20.0-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> <properties> |