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 52944 Details for
Bug 148041
[compiler][1.5] should issue unchecked warning on cast to Set<X> of Iterator#next () returning X
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
148041.txt (text/plain), 9.12 KB, created by
Philipe Mulet
on 2006-10-30 12:20:38 EST
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Philipe Mulet
Created:
2006-10-30 12:20:38 EST
Size:
9.12 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java,v >retrieving revision 1.106 >diff -u -r1.106 Expression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java 13 Oct 2006 19:20:45 -0000 1.106 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java 30 Oct 2006 17:24:33 -0000 >@@ -287,7 +287,7 @@ > // ( TYPE_PARAMETER ) ARRAY > TypeBinding match = expressionType.findSuperTypeWithSameErasure(castType); > if (match == null) { >- checkUnsafeCast(scope, castType, expressionType, match, true); >+ checkUnsafeCast(scope, castType, expressionType, null /*no match*/, true); > } > // recurse on the type variable upper bound > return checkCastTypesCompatibility(scope, ((TypeVariableBinding)castType).upperBound(), expressionType, expression); >@@ -341,7 +341,7 @@ > // ( INTERFACE ) TYPE_PARAMETER > match = expressionType.findSuperTypeWithSameErasure(castType); > if (match == null) { >- checkUnsafeCast(scope, castType, expressionType, match, true); >+ checkUnsafeCast(scope, castType, expressionType, null /*no match*/, true); > } > // recurse on the type variable upper bound > return checkCastTypesCompatibility(scope, ((TypeVariableBinding)castType).upperBound(), expressionType, expression); >@@ -360,6 +360,7 @@ > return checkUnsafeCast(scope, castType, interfaceType, match, true); > } > if (use15specifics) { >+ checkUnsafeCast(scope, castType, expressionType, null /*no match*/, true); > // ensure there is no collision between both interfaces: i.e. I1 extends List<String>, I2 extends List<Object> > if (interfaceType.hasIncompatibleSuperType((ReferenceBinding)castType)) > return false; >@@ -445,6 +446,7 @@ > return checkUnsafeCast(scope, castType, expressionType, match, true); > } > if (use15specifics) { >+ checkUnsafeCast(scope, castType, expressionType, null /*no match*/, true); > // ensure there is no collision between both interfaces: i.e. I1 extends List<String>, I2 extends List<Object> > if (refExprType.hasIncompatibleSuperType((ReferenceBinding) castType)) > return false; >Index: compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java,v >retrieving revision 1.105 >diff -u -r1.105 CastExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java 28 Oct 2006 04:11:27 -0000 1.105 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java 30 Oct 2006 17:24:33 -0000 >@@ -272,7 +272,7 @@ > } > > public boolean checkUnsafeCast(Scope scope, TypeBinding castType, TypeBinding expressionType, TypeBinding match, boolean isNarrowing) { >- if (match == castType) { >+ if (match == castType) { > if (!isNarrowing && match == this.resolvedType.leafComponentType()) { // do not tag as unnecessary when recursing through upper bounds > tagAsUnnecessaryCast(scope, castType); > } >@@ -301,6 +301,10 @@ > this.bits |= UnsafeCast; > return true; > } >+ if (match == null && castType.isBoundParameterizedType()) { // cast between unrelated types >+ this.bits |= UnsafeCast; >+ return true; >+ } > if (leafType.isTypeVariable()) { > this.bits |= UnsafeCast; > return true; >#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.549 >diff -u -r1.549 GenericTypeTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 30 Oct 2006 14:31:46 -0000 1.549 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 30 Oct 2006 17:24:49 -0000 >@@ -7357,6 +7357,11 @@ > " Set<X> channel = channels.get(0);\n" + > " ^^^^^^^^\n" + > "channels cannot be resolved\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 7)\n" + >+ " element = (Set<X>) iter.next();\n" + >+ " ^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The cast from X to Set<X> is actually checking against the erased type Set\n" + > "----------\n"); > } > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70243 unsafe cast when wildcards >@@ -26562,9 +26567,14 @@ > "1. WARNING in X.java (at line 5)\n" + > " return (Bar<Object>)f;\n" + > " ^^^^^^^^^^^^^^\n" + >+ "Type safety: The cast from Foo to Bar<Object> is actually checking against the erased type Bar\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 5)\n" + >+ " return (Bar<Object>)f;\n" + >+ " ^^^^^^^^^^^^^^\n" + > "Unnecessary cast from Foo to Bar<Object>\n" + > "----------\n" + >- "2. ERROR in X.java (at line 7)\n" + >+ "3. ERROR in X.java (at line 7)\n" + > " Zork z;\n" + > " ^^^^\n" + > "Zork cannot be resolved to a type\n" + >@@ -34170,4 +34180,96 @@ > }, > ""); > } >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148041 >+public void test1062() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", // ================= >+ "import java.util.HashSet;\n" + >+ "import java.util.Iterator;\n" + >+ "import java.util.Set;\n" + >+ "\n" + >+ "public class X {\n" + >+ " public static void main(String[] args) {\n" + >+ " Set<X> set = new HashSet<X>();\n" + >+ " for (Iterator<X> iterator = set.iterator(); iterator.hasNext();) {\n" + >+ " Set<X> element1 = iterator.next();\n" + >+ " Set<X> element2 = (Set<X>) iterator.next(); // warning\n" + >+ " }\n" + >+ " }\n" + >+ "}", // ================= >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 9)\n" + >+ " Set<X> element1 = iterator.next();\n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type mismatch: cannot convert from X to Set<X>\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 10)\n" + >+ " Set<X> element2 = (Set<X>) iterator.next(); // warning\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The cast from X to Set<X> is actually checking against the erased type Set\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148041 - variation >+public void test1063() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", // ================= >+ "import java.util.HashSet;\n" + >+ "import java.util.Iterator;\n" + >+ "import java.util.Set;\n" + >+ "\n" + >+ "public class X {\n" + >+ " public static void main(String[] args) {\n" + >+ " Set<Cloneable> set = new HashSet<Cloneable>();\n" + >+ " for (Iterator<Cloneable> iterator = set.iterator(); iterator.hasNext();) {\n" + >+ " Set<Cloneable> element1 = iterator.next();\n" + >+ " Set<Cloneable> element2 = (Set<Cloneable>) iterator.next(); // warning\n" + >+ " }\n" + >+ " }\n" + >+ "}", // ================= >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 9)\n" + >+ " Set<Cloneable> element1 = iterator.next();\n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type mismatch: cannot convert from Cloneable to Set<Cloneable>\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 10)\n" + >+ " Set<Cloneable> element2 = (Set<Cloneable>) iterator.next(); // warning\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The cast from Cloneable to Set<Cloneable> is actually checking against the erased type Set\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148041 - variation >+public void test1064() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", // ================= >+ "import java.util.HashSet;\n" + >+ "import java.util.Iterator;\n" + >+ "\n" + >+ "public class X {\n" + >+ " public static void main(String[] args) {\n" + >+ " HashSet<X> set = new HashSet<X>();\n" + >+ " for (Iterator<X> iterator = set.iterator(); iterator.hasNext();) {\n" + >+ " HashSet<X> element1 = iterator.next();\n" + >+ " HashSet<X> element2 = (HashSet<X>) iterator.next();\n" + >+ " }\n" + >+ " }\n" + >+ "}", // ================= >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 8)\n" + >+ " HashSet<X> element1 = iterator.next();\n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type mismatch: cannot convert from X to HashSet<X>\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 9)\n" + >+ " HashSet<X> element2 = (HashSet<X>) iterator.next();\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Cannot cast from X to HashSet<X>\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 148041
: 52944