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 175742 Details for
Bug 321085
Enhanced for loops need to implement type safety checks on array initializers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch under consideration
patch.txt (text/plain), 4.19 KB, created by
Srikanth Sankaran
on 2010-08-03 02:23:08 EDT
(
hide
)
Description:
Patch under consideration
Filename:
MIME Type:
Creator:
Srikanth Sankaran
Created:
2010-08-03 02:23:08 EDT
Size:
4.19 KB
patch
obsolete
>### 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<String> x = new HashSet<String>();\n" + >+ " x.add(\"a\");\n" + >+ " HashSet<Integer> y = new HashSet<Integer>();\n" + >+ " y.add(1);\n" + >+ " Set<String> [] OK= new Set[] { x, y };\n" + >+ " for (Set<String> 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<String> 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<String> [] OK= new Set[] { x, y };\n" + >+ " ^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The expression of type Set[] needs unchecked conversion to conform to Set<String>[]\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 10)\n" + >+ " for (Set<String> BUG : new Set[] { x, y }) {\n" + >+ " ^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The expression of type Set[] needs unchecked conversion to conform to Set<String>[]\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<E> should be parameterized\n" + >+ "----------\n" + >+ "4. WARNING in X.java (at line 15)\n" + >+ " for (Set<String> BUG : set) {\n" + >+ " ^^^\n" + >+ "Type safety: The expression of type Set[] needs unchecked conversion to conform to Set<String>[]\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; > }
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 321085
: 175742