### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties,v retrieving revision 1.245 diff -u -r1.245 messages.properties --- compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 24 Nov 2008 13:13:43 -0000 1.245 +++ compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 9 Dec 2008 14:20:43 -0000 @@ -471,8 +471,8 @@ 543 = Bound mismatch: The generic method {0}({1}) of type {2} is not applicable for the arguments ({3}). The inferred type {4} is not a valid substitute for the bounded parameter <{5} extends {6}> 544 = Bound mismatch: The generic constructor {0}({1}) of type {2} is not applicable for the arguments ({3}). The inferred type {4} is not a valid substitute for the bounded parameter <{5} extends {6}> 545 = Type safety: Unchecked cast from {0} to {1} -546 = Cannot perform instanceof check against parameterized type {0}. Use instead its raw form {1} since generic type information will be erased at runtime -547 = Cannot perform instanceof check against type parameter {0}. Use instead its erasure {1} since generic type information will be erased at runtime +546 = Cannot perform instanceof check against parameterized type {0}. Use the form {1} instead since further generic type information will be erased at runtime +547 = Cannot perform instanceof check against type parameter {0}. Use instead its erasure {1} instead since further generic type information will be erased at runtime 548 = The method {0}({1}) of type {2} is not generic; it cannot be parameterized with arguments <{3}> 549 = Incorrect number of type arguments for generic method <{3}>{0}({1}) of type {2}; it cannot be parameterized with arguments <{4}> 550 = The parameterized method <{3}>{0}({1}) of type {2} is not applicable for the arguments ({4}) Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java,v retrieving revision 1.384 diff -u -r1.384 ProblemReporter.java --- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 24 Nov 2008 13:13:43 -0000 1.384 +++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 9 Dec 2008 14:20:43 -0000 @@ -2071,19 +2071,37 @@ location.sourceEnd); } public void illegalInstanceOfGenericType(TypeBinding checkedType, ASTNode location) { - if (checkedType.isTypeVariable()) { + TypeBinding erasedType = checkedType.leafComponentType().erasure(); + StringBuffer recommendedFormBuffer = new StringBuffer(10); + recommendedFormBuffer.append(erasedType.sourceName()); + int count = erasedType.typeVariables().length; + if (count > 0) { + recommendedFormBuffer.append('<'); + for (int i = 0; i < count; i++) { + if (i > 0) { + recommendedFormBuffer.append(','); + } + recommendedFormBuffer.append('?'); + } + recommendedFormBuffer.append('>'); + } + for (int i = 0, dim = checkedType.dimensions(); i < dim; i++) { + recommendedFormBuffer.append("[]"); //$NON-NLS-1$ + } + String recommendedForm = recommendedFormBuffer.toString(); + if (checkedType.leafComponentType().isTypeVariable()) { this.handle( - IProblem.IllegalInstanceofTypeParameter, - new String[] { new String(checkedType.readableName()), new String(checkedType.erasure().readableName())}, - new String[] { new String(checkedType.shortReadableName()), new String(checkedType.erasure().shortReadableName())}, - location.sourceStart, - location.sourceEnd); + IProblem.IllegalInstanceofTypeParameter, + new String[] { new String(checkedType.readableName()), recommendedForm, }, + new String[] { new String(checkedType.shortReadableName()), recommendedForm, }, + location.sourceStart, + location.sourceEnd); return; } this.handle( IProblem.IllegalInstanceofParameterizedType, - new String[] { new String(checkedType.readableName()), new String(checkedType.erasure().sourceName())}, - new String[] { new String(checkedType.shortReadableName()), new String(checkedType.erasure().sourceName())}, + new String[] { new String(checkedType.readableName()), recommendedForm, }, + new String[] { new String(checkedType.shortReadableName()), recommendedForm, }, location.sourceStart, location.sourceEnd); } #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java,v retrieving revision 1.775 diff -u -r1.775 GenericTypeTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 8 Dec 2008 17:43:31 -0000 1.775 +++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 9 Dec 2008 14:20:52 -0000 @@ -5308,17 +5308,17 @@ "1. ERROR in X.java (at line 4)\n" + " if (t instanceof X) {\n" + " ^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type X. Use instead its raw form X since generic type information will be erased at runtime\n" + + "Cannot perform instanceof check against parameterized type X. Use the form X instead since further generic type information will be erased at runtime\n" + "----------\n" + "2. ERROR in X.java (at line 6)\n" + " } else if (t instanceof X) {\n" + " ^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type X. Use instead its raw form X since generic type information will be erased at runtime\n" + + "Cannot perform instanceof check against parameterized type X. Use the form X instead since further generic type information will be erased at runtime\n" + "----------\n" + "3. ERROR in X.java (at line 10)\n" + " } else if (t instanceof T) {\n" + " ^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against type parameter T. Use instead its erasure Object since generic type information will be erased at runtime\n" + + "Cannot perform instanceof check against type parameter T. Use instead its erasure Object instead since further generic type information will be erased at runtime\n" + "----------\n" + "4. WARNING in X.java (at line 12)\n" + " } else if (t instanceof X) {\n" + @@ -25733,36 +25733,36 @@ " }\n" + "}\n", }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " if (o instanceof E[]) { //incorrect: cannot test non-reifiable type\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type E[]. Use instead its raw form Object[] since generic type information will be erased at runtime\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " E[] es = (E[]) o;\n" + - " ^^^^^^^\n" + - "Type safety: Unchecked cast from Object to E[]\n" + - "----------\n" + - "3. ERROR in X.java (at line 7)\n" + - " if (o instanceof List[]) { //incorrect too\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type List[]. Use instead its raw form List[] since generic type information will be erased at runtime\n" + - "----------\n" + - "4. WARNING in X.java (at line 8)\n" + - " List[] es = (List[]) o; \n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to List[]\n" + - "----------\n" + - "5. ERROR in X.java (at line 15)\n" + - " if (al instanceof List[]) { //incorrect too\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type List[]. Use instead its raw form List[] since generic type information will be erased at runtime\n" + - "----------\n" + - "6. WARNING in X.java (at line 16)\n" + - " List[] es = (List[]) al; \n" + - " ^^^^^^^^^^^^^^\n" + - "Unnecessary cast from ArrayList[] to List[]\n" + + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o instanceof E[]) { //incorrect: cannot test non-reifiable type\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against type parameter E[]. Use instead its erasure Object[] instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " E[] es = (E[]) o;\n" + + " ^^^^^^^\n" + + "Type safety: Unchecked cast from Object to E[]\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " if (o instanceof List[]) { //incorrect too\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List[]. Use the form List[] instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " List[] es = (List[]) o; \n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List[]\n" + + "----------\n" + + "5. ERROR in X.java (at line 15)\n" + + " if (al instanceof List[]) { //incorrect too\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List[]. Use the form List[] instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "6. WARNING in X.java (at line 16)\n" + + " List[] es = (List[]) al; \n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from ArrayList[] to List[]\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 - variation @@ -25803,16 +25803,16 @@ " }\n" + "}\n", }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " if (o instanceof List[][]) { //incorrect too\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type List[][]. Use instead its raw form List[][] since generic type information will be erased at runtime\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " List[][] es = (List[][]) o; \n" + - " ^^^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object[] to List[][]\n" + + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o instanceof List[][]) { //incorrect too\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List[][]. Use the form List[][] instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " List[][] es = (List[][]) o; \n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object[] to List[][]\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 - variation @@ -25843,51 +25843,51 @@ " }\n" + "}\n", }, - "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " private T t;\n" + - " ^\n" + - "The field X.t is never read locally\n" + - "----------\n" + - "2. WARNING in X.java (at line 9)\n" + - " if (this.inner instanceof X.Inner) {}\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The expression of type X.Inner is already an instance of type X.Inner\n" + - "----------\n" + - "3. WARNING in X.java (at line 10)\n" + - " if (this.inners instanceof X.Inner[]) {}\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The expression of type X.Inner[] is already an instance of type X.Inner[]\n" + - "----------\n" + - "4. WARNING in X.java (at line 14)\n" + - " void foo(List l) {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "5. WARNING in X.java (at line 15)\n" + - " if (l instanceof List) {}\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "The expression of type List is already an instance of type List\n" + - "----------\n" + - "6. ERROR in X.java (at line 16)\n" + - " if (l instanceof List) {}\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type List. Use instead its raw form List since generic type information will be erased at runtime\n" + - "----------\n" + - "7. WARNING in X.java (at line 18)\n" + - " void foo(List[] ls) {\n" + - " ^^^^\n" + - "List is a raw type. References to generic type List should be parameterized\n" + - "----------\n" + - "8. WARNING in X.java (at line 19)\n" + - " if (ls instanceof List[]) {}\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The expression of type List[] is already an instance of type List\n" + - "----------\n" + - "9. ERROR in X.java (at line 20)\n" + - " if (ls instanceof List[]) {}\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type List[]. Use instead its raw form List[] since generic type information will be erased at runtime\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " private T t;\n" + + " ^\n" + + "The field X.t is never read locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " if (this.inner instanceof X.Inner) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type X.Inner is already an instance of type X.Inner\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " if (this.inners instanceof X.Inner[]) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type X.Inner[] is already an instance of type X.Inner[]\n" + + "----------\n" + + "4. WARNING in X.java (at line 14)\n" + + " void foo(List l) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 15)\n" + + " if (l instanceof List) {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The expression of type List is already an instance of type List\n" + + "----------\n" + + "6. ERROR in X.java (at line 16)\n" + + " if (l instanceof List) {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List. Use the form List instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "7. WARNING in X.java (at line 18)\n" + + " void foo(List[] ls) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 19)\n" + + " if (ls instanceof List[]) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type List[] is already an instance of type List\n" + + "----------\n" + + "9. ERROR in X.java (at line 20)\n" + + " if (ls instanceof List[]) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List[]. Use the form List[] instead since further generic type information will be erased at runtime\n" + "----------\n"); } public void test0818() { @@ -30956,16 +30956,16 @@ " }\n" + "}\n", }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " if (o instanceof List[]) { //incorrect: bug 104695\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot perform instanceof check against parameterized type List[]. Use instead its raw form List[] since generic type information will be erased at runtime\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + - " List[] es= (List[]) o; //unchecked\n" + - " ^^^^^^^^^^^^^\n" + - "Type safety: Unchecked cast from Object to List[]\n" + + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o instanceof List[]) { //incorrect: bug 104695\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List[]. Use the form List[] instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " List[] es= (List[]) o; //unchecked\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List[]\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=130128 @@ -48262,4 +48262,47 @@ "Type mismatch: cannot convert from Class to Class>\n" + "----------\n"); } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258039 +public void test1426() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.*;\n" + + "public class X {\n" + + " boolean foo() {\n" + + " return null instanceof List;\n" + + " }\n" + + " > boolean foo2() {\n" + + " return null instanceof T;\n" + + " }\n" + + " boolean foo3() {\n" + + " return null instanceof Map;\n" + + " }\n" + + " > boolean foo4() {\n" + + " return null instanceof T;\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return null instanceof List;\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List. Use the form List instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " return null instanceof T;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against type parameter T. Use instead its erasure List instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " return null instanceof Map;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type Map. Use the form Map instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " return null instanceof T;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against type parameter T. Use instead its erasure Map instead since further generic type information will be erased at runtime\n" + + "----------\n"); +} } \ No newline at end of file