### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java,v retrieving revision 1.63 diff -u -r1.63 ForeachStatement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java 7 Jan 2010 20:18:49 -0000 1.63 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java 3 Aug 2010 06:21:41 -0000 @@ -388,6 +388,8 @@ if (!this.collectionElementType.isCompatibleWith(elementType) && !this.scope.isBoxingCompatibleWith(this.collectionElementType, elementType)) { this.scope.problemReporter().notCompatibleTypesErrorInForeach(this.collection, this.collectionElementType, elementType); + } else if (this.collectionElementType.needsUncheckedConversion(elementType)) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=321085 + this.scope.problemReporter().unsafeTypeConversion(this.collection, collectionType, upperScope.createArrayType(elementType, 1)); } // in case we need to do a conversion int compileTimeTypeID = this.collectionElementType.id; #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java,v retrieving revision 1.46 diff -u -r1.46 ForeachStatementTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java 11 May 2010 18:53:50 -0000 1.46 +++ src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java 3 Aug 2010 06:21:49 -0000 @@ -2779,6 +2779,60 @@ }, "12345"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=321085 +public void test054() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.HashSet;\n" + + "import java.util.Set;\n" + + "public class X {\n" + + " void foo() {\n" + + " HashSet x = new HashSet();\n" + + " x.add(\"a\");\n" + + " HashSet y = new HashSet();\n" + + " y.add(1);\n" + + " Set [] OK= new Set[] { x, y };\n" + + " for (Set BUG : new Set[] { x, y }) {\n" + + " for (String str : BUG)\n" + + " System.out.println(str);\n" + + " }\n" + + " Set [] set = new Set[] { x, y };\n" + + " for (Set BUG : set) {\n" + + " for (String str : BUG)\n" + + " System.out.println(str);\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Set [] OK= new Set[] { x, y };\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Set[] needs unchecked conversion to conform to Set[]\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " for (Set BUG : new Set[] { x, y }) {\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Set[] needs unchecked conversion to conform to Set[]\n" + + "----------\n" + + "3. WARNING in X.java (at line 14)\n" + + " Set [] set = new Set[] { x, y };\n" + + " ^^^\n" + + "Set is a raw type. References to generic type Set should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 15)\n" + + " for (Set BUG : set) {\n" + + " ^^^\n" + + "Type safety: The expression of type Set[] needs unchecked conversion to conform to Set[]\n" + + "----------\n" + + "5. ERROR in X.java (at line 20)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} public static Class testClass() { return ForeachStatementTest.class; }