Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2020-04-23 09:02:43 +0000
committerJay Arthanareeswaran2020-04-24 07:44:12 +0000
commitee3ca7af25d58effe0bfa136078955ba02fff70e (patch)
treed2e4a84c01688aafb5900f4d4e9435dec1183f17
parentaeb10adbe3092fd61d30a2461995af2907731d3a (diff)
downloadeclipse.jdt.core-ee3ca7af25d58effe0bfa136078955ba02fff70e.tar.gz
eclipse.jdt.core-ee3ca7af25d58effe0bfa136078955ba02fff70e.tar.xz
eclipse.jdt.core-ee3ca7af25d58effe0bfa136078955ba02fff70e.zip
Revert "Bug 562392 - [14] Type parameters should be allowed in
instanceof" This only reverts the fix but retains the new tests in disabled condition This reverts commit 7bd737f958efefb05ab8cc567eff85d4f5efca69. Change-Id: I6b5d466580a27dd9d94ad75c5985f9bad47ca618
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java57
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java117
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching14Test.java80
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java4
4 files changed, 159 insertions, 99 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
index a97c29f664..9e73da19fe 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2020 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -5358,8 +5358,6 @@ public class GenericTypeTest extends AbstractComparableTest {
}
// reject instanceof type variable or parameterized type
public void test0178() {
- if (this.complianceLevel >= ClassFileConstants.JDK14)
- return;
Map customOptions = getCompilerOptions();
this.runNegativeTest(
new String[] {
@@ -5402,6 +5400,47 @@ public class GenericTypeTest extends AbstractComparableTest {
true,
customOptions);
}
+ public void _test0178a() {
+ if (this.complianceLevel < ClassFileConstants.JDK14)
+ return;
+ Map customOptions = getCompilerOptions();
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X <T> {\n" +
+ " \n" +
+ " T foo(T t) {\n" +
+ " boolean b = false;\n" +
+ " if (t instanceof X<T>) {\n" +
+ " return t;\n" +
+ " } else if (t instanceof X<String>) {\n" +
+ " return t;\n" +
+ " } else if (t instanceof X<?>) {\n" + // ok
+ " return t;\n" +
+ " } else if (t instanceof T) {\n" +
+ " return t;\n" +
+ " } else if (t instanceof X) {\n" +
+ " return t;\n" +
+ " }\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " if (t instanceof X<T>) {\n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "Type mismatch: cannot convert from T to X<T>\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " } else if (t instanceof X<String>) {\n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "Type mismatch: cannot convert from T to X<String>\n" +
+ "----------\n",
+ null,
+ true,
+ customOptions);
+ }
// 61507
public void test0179() {
this.runConformTest(
@@ -26370,8 +26409,6 @@ public void test0813() {
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695
public void test0814() {
- if (this.complianceLevel >= ClassFileConstants.JDK14)
- return;
this.runNegativeTest(
new String[] {
"X.java",
@@ -26453,8 +26490,6 @@ public void test0815() {
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 - variation
public void test0816() {
- if (this.complianceLevel >= ClassFileConstants.JDK14)
- return;
this.runNegativeTest(
new String[] {
"X.java",
@@ -26481,8 +26516,6 @@ public void test0816() {
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 - variation
public void test0817() {
- if (this.complianceLevel >= ClassFileConstants.JDK14)
- return;
this.runNegativeTest(
new String[] {
"X.java",
@@ -31926,8 +31959,6 @@ public void test0954() {
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105049
public void test0955() {
- if (this.complianceLevel >= ClassFileConstants.JDK14)
- return;
this.runNegativeTest(
new String[] {
"X.java", //================================
@@ -50134,8 +50165,6 @@ public void test1425() {
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258039
public void test1426() {
- if (this.complianceLevel >= ClassFileConstants.JDK14)
- return;
this.runNegativeTest(
new String[] {
"X.java", //-----------------------------------------------------------------------
@@ -51697,8 +51726,6 @@ public void test268798a() {
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=307885
public void test1460() {
- if (this.complianceLevel >= ClassFileConstants.JDK14)
- return;
this.runNegativeTest(
new String[] {
"Test.java",
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
index 11e7d01c02..22722bf014 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
@@ -2270,8 +2270,31 @@ public class NullTypeAnnotationTest extends AbstractNullAnnotationTest {
// illegal / unchecked for cast & instanceof with complex type
public void testUnsupportedLocation04() {
- String expectedProblemLog =
- (this.complianceLevel < ClassFileConstants.JDK14) ?
+ runNegativeTest(
+ new String[] {
+ "p/X.java",
+ "package p;\n" +
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "import java.util.*;\n" +
+ "public class X {\n" +
+ " List<@NonNull X> parameterized(List<X> arg) {\n" +
+ " if (!(arg instanceof List<@NonNull X>))\n" +
+ " return (java.util.List<@NonNull X>)arg;\n" +
+ " return arg;\n" +
+ " }\n" +
+ " X @NonNull[] arrays(X[] arg) {\n" +
+ " if (!(arg instanceof X @NonNull[]))\n" +
+ " return (p.X @NonNull[])arg;\n" +
+ " return arg;\n" +
+ " }\n" +
+ " ArrayList<@NonNull String> foo(List<@NonNull String> l) {\n" +
+ " return (ArrayList<@NonNull String>) l;\n" + // OK
+ " }" +
+ " ArrayList<@NonNull String> foo2(List<@NonNull String> l) {\n" +
+ " return (ArrayList<String>) l;\n" + // warn, TODO(stephan) with flow analysis (bug 415292) we might recover the original @NonNull...
+ " }" +
+ "}\n"
+ },
"----------\n" +
"1. ERROR in p\\X.java (at line 6)\n" +
" if (!(arg instanceof List<@NonNull X>))\n" +
@@ -2307,64 +2330,7 @@ public class NullTypeAnnotationTest extends AbstractNullAnnotationTest {
" return (ArrayList<String>) l;\n" +
" ^^^^^^^^^^^^^^^^^^^^^\n" +
"Null type safety (type annotations): The expression of type \'ArrayList<String>\' needs unchecked conversion to conform to \'ArrayList<@NonNull String>\'\n" +
- "----------\n" :
- "----------\n" +
- "1. ERROR in p\\X.java (at line 6)\n" +
- " if (!(arg instanceof List<@NonNull X>))\n" +
- " ^^^^^^^^^^^^^^^^\n" +
- "Nullness annotations are not applicable at this location \n" +
- "----------\n" +
- "2. WARNING in p\\X.java (at line 7)\n" +
- " return (java.util.List<@NonNull X>)arg;\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type safety: Unchecked cast from List<X> to List<@NonNull X>\n" +
- "----------\n" +
- "3. WARNING in p\\X.java (at line 11)\n" +
- " if (!(arg instanceof X @NonNull[]))\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "The expression of type X[] is already an instance of type X[]\n" +
- "----------\n" +
- "4. ERROR in p\\X.java (at line 11)\n" +
- " if (!(arg instanceof X @NonNull[]))\n" +
- " ^^^^^^^^^^^^\n" +
- "Nullness annotations are not applicable at this location \n" +
- "----------\n" +
- "5. WARNING in p\\X.java (at line 12)\n" +
- " return (p.X @NonNull[])arg;\n" +
- " ^^^^^^^^^^^^^^^^^^^\n" +
- "Null type safety: Unchecked cast from X[] to X @NonNull[]\n" +
- "----------\n" +
- "6. WARNING in p\\X.java (at line 18)\n" +
- " return (ArrayList<String>) l;\n" +
- " ^^^^^^^^^^^^^^^^^^^^^\n" +
- "Null type safety (type annotations): The expression of type \'ArrayList<String>\' needs unchecked conversion to conform to \'ArrayList<@NonNull String>\'\n" +
- "----------\n";
- runNegativeTest(
- new String[] {
- "p/X.java",
- "package p;\n" +
- "import org.eclipse.jdt.annotation.*;\n" +
- "import java.util.*;\n" +
- "public class X {\n" +
- " List<@NonNull X> parameterized(List<X> arg) {\n" +
- " if (!(arg instanceof List<@NonNull X>))\n" +
- " return (java.util.List<@NonNull X>)arg;\n" +
- " return arg;\n" +
- " }\n" +
- " X @NonNull[] arrays(X[] arg) {\n" +
- " if (!(arg instanceof X @NonNull[]))\n" +
- " return (p.X @NonNull[])arg;\n" +
- " return arg;\n" +
- " }\n" +
- " ArrayList<@NonNull String> foo(List<@NonNull String> l) {\n" +
- " return (ArrayList<@NonNull String>) l;\n" + // OK
- " }" +
- " ArrayList<@NonNull String> foo2(List<@NonNull String> l) {\n" +
- " return (ArrayList<String>) l;\n" + // warn, TODO(stephan) with flow analysis (bug 415292) we might recover the original @NonNull...
- " }" +
- "}\n"
- },
- expectedProblemLog,
+ "----------\n",
this.LIBS,
true/*flush*/);
}
@@ -8442,25 +8408,6 @@ public void testBug466713c() {
}
// variant for https://bugs.eclipse.org/bugs/show_bug.cgi?id=466713#c5
public void testBug466713d() {
- String expectedProblemLog =
- (this.complianceLevel < ClassFileConstants.JDK14) ?
- "----------\n" +
- "1. ERROR in Bug.java (at line 3)\n" +
- " return o instanceof java.util.Iterator<java.lang. @MyAnnot @org.eclipse.jdt.annotation.Nullable String>;\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Cannot perform instanceof check against parameterized type Iterator<String>. Use the form Iterator<?> instead since further generic type information will be erased at runtime\n" +
- "----------\n" +
- "2. ERROR in Bug.java (at line 3)\n" +
- " return o instanceof java.util.Iterator<java.lang. @MyAnnot @org.eclipse.jdt.annotation.Nullable String>;\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Nullness annotations are not applicable at this location \n" +
- "----------\n" :
- "----------\n" +
- "1. ERROR in Bug.java (at line 3)\n" +
- " return o instanceof java.util.Iterator<java.lang. @MyAnnot @org.eclipse.jdt.annotation.Nullable String>;\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Nullness annotations are not applicable at this location \n" +
- "----------\n";
runNegativeTest(
new String[] {
"MyAnnot.java",
@@ -8475,7 +8422,17 @@ public void testBug466713d() {
" }\n" +
"}\n"
},
- expectedProblemLog,
+ "----------\n" +
+ "1. ERROR in Bug.java (at line 3)\n" +
+ " return o instanceof java.util.Iterator<java.lang. @MyAnnot @org.eclipse.jdt.annotation.Nullable String>;\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Cannot perform instanceof check against parameterized type Iterator<String>. Use the form Iterator<?> instead since further generic type information will be erased at runtime\n" +
+ "----------\n" +
+ "2. ERROR in Bug.java (at line 3)\n" +
+ " return o instanceof java.util.Iterator<java.lang. @MyAnnot @org.eclipse.jdt.annotation.Nullable String>;\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Nullness annotations are not applicable at this location \n" +
+ "----------\n",
this.LIBS,
true/*flush*/);
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching14Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching14Test.java
index 95faee0fd8..dab2d3f34b 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching14Test.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching14Test.java
@@ -2045,7 +2045,7 @@ public class PatternMatching14Test extends AbstractRegressionTest {
compilerOptions);
compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, old);
}
- public void testBug562392() {
+ public void _testBug562392a() {
Map<String, String> compilerOptions = getCompilerOptions(true);
runConformTest(
new String[] {
@@ -2067,4 +2067,82 @@ public class PatternMatching14Test extends AbstractRegressionTest {
"true",
compilerOptions);
}
+ public void _testBug562392b() {
+ Map<String, String> compilerOptions = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X<T> {\n" +
+ " public boolean foo(Object obj) {\n" +
+ " if (obj instanceof T) {\n" +
+ " return false;\n" +
+ " }\n" +
+ " return true;\n" +
+ " }\n" +
+ " public static void main(String argv[]) {\n" +
+ " System.out.println(\"\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " if (obj instanceof T) {\n" +
+ " ^^^^^^^^^^^^^^^^\n" +
+ "Type mismatch: cannot convert from Object to T\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ compilerOptions);
+ }
+ public void _testBug562392c() {
+ Map<String, String> compilerOptions = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X<T> {\n" +
+ " public boolean foo(Object obj) {\n" +
+ " if (obj instanceof T t) {\n" +
+ " return false;\n" +
+ " }\n" +
+ " return true;\n" +
+ " }\n" +
+ " public static void main(String argv[]) {\n" +
+ " System.out.println(\"\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " if (obj instanceof T t) {\n" +
+ " ^^^^^^^^^^^^^^^^^^\n" +
+ "Type mismatch: cannot convert from Object to T\n" +
+ "----------\n",
+ "",
+ null,
+ true,
+ compilerOptions);
+ }
+ public void _testBug562392d() {
+ Map<String, String> compilerOptions = getCompilerOptions(true);
+ runConformTest(
+ new String[] {
+ "X.java",
+ "@SuppressWarnings(\"preview\")\n" +
+ "public class X<T> {\n" +
+ " public boolean foo(Object obj) {\n" +
+ " if (null instanceof T t) {\n" +
+ " return false;\n" +
+ " }\n" +
+ " return true;\n" +
+ " }\n" +
+ " public static void main(String argv[]) {\n" +
+ " System.out.println(\"\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "",
+ compilerOptions);
+ }
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java
index c7524c37c2..3ca65a79e0 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java
@@ -26,7 +26,6 @@ package org.eclipse.jdt.internal.compiler.ast;
import org.eclipse.jdt.internal.compiler.ASTVisitor;
import org.eclipse.jdt.internal.compiler.ast.TypeReference.AnnotationPosition;
-import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.codegen.*;
import org.eclipse.jdt.internal.compiler.flow.*;
import org.eclipse.jdt.internal.compiler.impl.Constant;
@@ -177,8 +176,7 @@ public TypeBinding resolveType(BlockScope scope) {
return null;
if (!checkedType.isReifiable()) {
- if (scope.compilerOptions().complianceLevel < ClassFileConstants.JDK14)
- scope.problemReporter().illegalInstanceOfGenericType(checkedType, this);
+ scope.problemReporter().illegalInstanceOfGenericType(checkedType, this);
} else if (checkedType.isValidBinding()) {
// if not a valid binding, an error has already been reported for unresolved type
if ((expressionType != TypeBinding.NULL && expressionType.isBaseType()) // disallow autoboxing

Back to the top