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 119898 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]
Proposed patch
258039.txt (text/plain), 7.16 KB, created by
Philipe Mulet
on 2008-12-09 07:59:07 EST
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Philipe Mulet
Created:
2008-12-09 07:59:07 EST
Size:
7.16 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 12:58:38 -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 12:58:38 -0000 >@@ -2071,19 +2071,34 @@ > location.sourceEnd); > } > public void illegalInstanceOfGenericType(TypeBinding checkedType, ASTNode location) { >+ TypeBinding erasedType = checkedType.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('>'); >+ } >+ String recommendedForm = recommendedFormBuffer.toString(); > if (checkedType.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())}, >+ 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 12:58:46 -0000 >@@ -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