Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Johnston2019-01-24 20:44:07 +0000
committerStephan Herrmann2019-02-07 20:13:11 +0000
commit56c7200f17bcd06f03618a81316a7dbfe1d7dcf8 (patch)
tree87cd95708160d891a81b66b36b725bb9c5591a5a /org.eclipse.jdt.core.tests.compiler/src
parentbcec7451e941decddf86ddcdbe87a1f9b59eec30 (diff)
downloadeclipse.jdt.core-56c7200f17bcd06f03618a81316a7dbfe1d7dcf8.tar.gz
eclipse.jdt.core-56c7200f17bcd06f03618a81316a7dbfe1d7dcf8.tar.xz
eclipse.jdt.core-56c7200f17bcd06f03618a81316a7dbfe1d7dcf8.zip
Bug 543727 - False positive "Unnecessary cast"I20190207-1800
- change EqualExpression.resolveType() to add additional check before reporting an unnecessary cast if one side is parameterized and the other is a cast of a base type that may be compatible with parameterized type when boxed - add test to CastTest Change-Id: I9e3e1be9a0d42965dba9c8dbf629171248d0b26b Signed-off-by: Jeff Johnston <jjohnstn@redhat.com>
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/CastTest.java50
1 files changed, 49 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java
index e723cdbad6..e0e23ca878 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2017 IBM Corporation and others.
+ * Copyright (c) 2003, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -3297,6 +3297,54 @@ public void testAnonymous_bug520727() {
runConformTest(source,"");
}
}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=543727 False positive "Unnecessary cast"
+public void test543727() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_7)
+ return;
+ Map customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR);
+ this.runConformTest(
+ new String[] {
+ "Bug.java",
+ "import java.util.ArrayList;\n" +
+ "import java.util.List;\n" +
+ "public class Bug {\n" +
+ " public static int main(String[] args) {\n" +
+ " List<Comparable<?>> vector = new ArrayList<>();\n" +
+ " vector.add(0);\n" +
+ " if (vector.get(0) == (Integer)0) {\n" +
+ " System.out.print(\"SUCCESS\");\n" +
+ " }\n" +
+ " return 0;\n" +
+ " }" +
+ "}\n",
+ },
+ "SUCCESS");
+}
+public void test543727_notequals() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_7)
+ return;
+ Map customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR);
+ this.runConformTest(
+ new String[] {
+ "Bug.java",
+ "import java.util.ArrayList;\n" +
+ "import java.util.List;\n" +
+ "public class Bug {\n" +
+ " public static int main(String[] args) {\n" +
+ " List<Comparable<?>> vector = new ArrayList<>();\n" +
+ " vector.add(0);\n" +
+ " if (vector.get(0) != (Integer)1) {\n" +
+ " System.out.print(\"SUCCESS\");\n" +
+ " }\n" +
+ " return 0;\n" +
+ " }" +
+ "}\n",
+ },
+ "SUCCESS");
+}
+
public static Class testClass() {
return CastTest.class;
}

Back to the top