Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 119906 Details for
Bug 258039
[1.5][compiler] Misleading error message for "instanceof List<Object>"
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Better patch
258039.txt (text/plain), 19.38 KB, created by
Philipe Mulet
on 2008-12-09 09:21:39 EST
(
hide
)
Description:
Better patch
Filename:
MIME Type:
Creator:
Philipe Mulet
Created:
2008-12-09 09:21:39 EST
Size:
19.38 KB
patch
obsolete
>### 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<T>) {\n" + > " ^^^^^^^^^^^^^^\n" + >- "Cannot perform instanceof check against parameterized type X<T>. Use instead its raw form X since generic type information will be erased at runtime\n" + >+ "Cannot perform instanceof check against parameterized type X<T>. 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<String>) {\n" + > " ^^^^^^^^^^^^^^\n" + >- "Cannot perform instanceof check against parameterized type X<String>. Use instead its raw form X since generic type information will be erased at runtime\n" + >+ "Cannot perform instanceof check against parameterized type X<String>. 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<E>[]) { //incorrect too\n" + >- " ^^^^^^^^^^^^^^^^^^^^^^\n" + >- "Cannot perform instanceof check against parameterized type List<E>[]. 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<E>[] es = (List<E>[]) o; \n" + >- " ^^^^^^^^^^^^^\n" + >- "Type safety: Unchecked cast from Object to List<E>[]\n" + >- "----------\n" + >- "5. ERROR in X.java (at line 15)\n" + >- " if (al instanceof List<E>[]) { //incorrect too\n" + >- " ^^^^^^^^^^^^^^^^^^^^^^^\n" + >- "Cannot perform instanceof check against parameterized type List<E>[]. 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<E>[] es = (List<E>[]) al; \n" + >- " ^^^^^^^^^^^^^^\n" + >- "Unnecessary cast from ArrayList<E>[] to List<E>[]\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<E>[]) { //incorrect too\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Cannot perform instanceof check against parameterized type List<E>[]. 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<E>[] es = (List<E>[]) o; \n" + >+ " ^^^^^^^^^^^^^\n" + >+ "Type safety: Unchecked cast from Object to List<E>[]\n" + >+ "----------\n" + >+ "5. ERROR in X.java (at line 15)\n" + >+ " if (al instanceof List<E>[]) { //incorrect too\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Cannot perform instanceof check against parameterized type List<E>[]. 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<E>[] es = (List<E>[]) al; \n" + >+ " ^^^^^^^^^^^^^^\n" + >+ "Unnecessary cast from ArrayList<E>[] to List<E>[]\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<E>[][]) { //incorrect too\n" + >- " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + >- "Cannot perform instanceof check against parameterized type List<E>[][]. 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<E>[][] es = (List<E>[][]) o; \n" + >- " ^^^^^^^^^^^^^^^\n" + >- "Type safety: Unchecked cast from Object[] to List<E>[][]\n" + >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\n" + >+ " if (o instanceof List<E>[][]) { //incorrect too\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Cannot perform instanceof check against parameterized type List<E>[][]. 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<E>[][] es = (List<E>[][]) o; \n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type safety: Unchecked cast from Object[] to List<E>[][]\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>.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<E> 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<? extends String>) {}\n" + >- " ^^^^^^^^^^^^^^^^^\n" + >- "Cannot perform instanceof check against parameterized type List<? extends String>. 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<E> 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<? extends String>[]) {}\n" + >- " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >- "Cannot perform instanceof check against parameterized type List<? extends String>[]. 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>.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<E> 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<? extends String>) {}\n" + >+ " ^^^^^^^^^^^^^^^^^\n" + >+ "Cannot perform instanceof check against parameterized type List<? extends String>. 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<E> 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<? extends String>[]) {}\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Cannot perform instanceof check against parameterized type List<? extends String>[]. 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<E>[]) { //incorrect: bug 104695\n" + >- " ^^^^^^^^^^^^^^^^^^^^^^\n" + >- "Cannot perform instanceof check against parameterized type List<E>[]. 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<E>[] es= (List<E>[]) o; //unchecked\n" + >- " ^^^^^^^^^^^^^\n" + >- "Type safety: Unchecked cast from Object to List<E>[]\n" + >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\n" + >+ " if (o instanceof List<E>[]) { //incorrect: bug 104695\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Cannot perform instanceof check against parameterized type List<E>[]. 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<E>[] es= (List<E>[]) o; //unchecked\n" + >+ " ^^^^^^^^^^^^^\n" + >+ "Type safety: Unchecked cast from Object to List<E>[]\n" + > "----------\n"); > } > //https://bugs.eclipse.org/bugs/show_bug.cgi?id=130128 >@@ -48262,4 +48262,47 @@ > "Type mismatch: cannot convert from Class<capture#6-of ? extends YYY> to Class<? extends YYY<? extends B>>\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<Object>;\n" + >+ " }\n" + >+ " <T extends List<Object>> boolean foo2() {\n" + >+ " return null instanceof T;\n" + >+ " }\n" + >+ " boolean foo3() {\n" + >+ " return null instanceof Map<Object,String>;\n" + >+ " }\n" + >+ " <T extends Map<Object,String>> boolean foo4() {\n" + >+ " return null instanceof T;\n" + >+ " }\n" + >+ "}\n",//----------------------------------------------------------------------- >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\n" + >+ " return null instanceof List<Object>;\n" + >+ " ^^^^^^^^^^^^^^^^^^^^\n" + >+ "Cannot perform instanceof check against parameterized type List<Object>. 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<Object,String>;\n" + >+ " ^^^^^^^^^^^^^^^^^^^\n" + >+ "Cannot perform instanceof check against parameterized type Map<Object,String>. 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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 258039
:
119898
| 119906