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 191197 Details for
Bug 337962
COMPILER_PB_UNAVOIDABLE_GENERIC_TYPE_PROBLEMS misses reference to field from supertype
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch under consideration
patch.txt (text/plain), 17.95 KB, created by
Srikanth Sankaran
on 2011-03-15 05:11:33 EDT
(
hide
)
Description:
Patch under consideration
Filename:
MIME Type:
Creator:
Srikanth Sankaran
Created:
2011-03-15 05:11:33 EDT
Size:
17.95 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.134 >diff -u -r1.134 Expression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java 15 Mar 2011 05:44:24 -0000 1.134 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java 15 Mar 2011 09:10:48 -0000 >@@ -27,6 +27,7 @@ > import org.eclipse.jdt.internal.compiler.lookup.Binding; > import org.eclipse.jdt.internal.compiler.lookup.BlockScope; > import org.eclipse.jdt.internal.compiler.lookup.ClassScope; >+import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; > import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; > import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; > import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; >@@ -968,13 +969,28 @@ > /** > * Returns true if the receiver is forced to be of raw type either to satisfy the contract imposed > * by a super type or because it *is* raw and the current type has no control over it (i.e the rawness >- * originates from some other file. >+ * originates from some other file.) > */ > public boolean forcedToBeRaw(ReferenceContext referenceContext) { > if (this instanceof NameReference) { > final Binding receiverBinding = ((NameReference) this).binding; > if (receiverBinding.isParameter() && (((LocalVariableBinding) receiverBinding).tagBits & TagBits.ForcedToBeRawType) != 0) { > return true; // parameter is forced to be raw since super method uses raw types. >+ } else if (receiverBinding instanceof FieldBinding) { >+ FieldBinding field = (FieldBinding) receiverBinding; >+ if (field.type.isRawType()) { >+ if (referenceContext instanceof AbstractMethodDeclaration) { >+ AbstractMethodDeclaration methodDecl = (AbstractMethodDeclaration) referenceContext; >+ if (field.declaringClass != methodDecl.binding.declaringClass) { // inherited raw field, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=337962 >+ return true; >+ } >+ } else if (referenceContext instanceof TypeDeclaration) { >+ TypeDeclaration type = (TypeDeclaration) referenceContext; >+ if (field.declaringClass != type.binding) { // inherited raw field, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=337962 >+ return true; >+ } >+ } >+ } > } > } else if (this instanceof MessageSend) { > if (!CharOperation.equals(((MessageSend) this).binding.declaringClass.getFileName(), >@@ -982,10 +998,24 @@ > return true; > } > } else if (this instanceof FieldReference) { >- if (!CharOperation.equals(((FieldReference) this).binding.declaringClass.getFileName(), >+ FieldBinding field = ((FieldReference) this).binding; >+ if (!CharOperation.equals(field.declaringClass.getFileName(), > referenceContext.compilationResult().getFileName())) { // problem is rooted elsewhere > return true; > } >+ if (field.type.isRawType()) { >+ if (referenceContext instanceof AbstractMethodDeclaration) { >+ AbstractMethodDeclaration methodDecl = (AbstractMethodDeclaration) referenceContext; >+ if (field.declaringClass != methodDecl.binding.declaringClass) { // inherited raw field, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=337962 >+ return true; >+ } >+ } else if (referenceContext instanceof TypeDeclaration) { >+ TypeDeclaration type = (TypeDeclaration) referenceContext; >+ if (field.declaringClass != type.binding) { // inherited raw field, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=337962 >+ return true; >+ } >+ } >+ } > } else if (this instanceof ConditionalExpression) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337751 > ConditionalExpression ternary = (ConditionalExpression) this; > if (ternary.valueIfTrue.forcedToBeRaw(referenceContext) || ternary.valueIfFalse.forcedToBeRaw(referenceContext)) { >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java,v >retrieving revision 1.8 >diff -u -r1.8 GenericsRegressionTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java 15 Mar 2011 05:44:19 -0000 1.8 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java 15 Mar 2011 09:11:13 -0000 >@@ -1460,4 +1460,284 @@ > compilerOptions15, > null); > } >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=337962 >+public void test337962() { >+ Map compilerOptions15 = getCompilerOptions(); >+ compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); >+ compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); >+ compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); >+ compilerOptions15.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "import java.util.List;\n" + >+ "import java.util.ArrayList;\n" + >+ "class Super {\n" + >+ " protected List fList;\n" + >+ "}\n" + >+ "public class X extends Super {\n" + >+ " protected List fSubList; // raw type warning (good)\n" + >+ " {\n" + >+ " fSubList = new ArrayList();\n " + >+ " fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" + >+ " super.fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" + >+ " fSubList.add(null); // type safety warning (good, should not be hidden)\n" + >+ " }\n" + >+ " void foo(String s) {\n" + >+ " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + >+ " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + >+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + >+ " }\n" + >+ " X(String s) {\n" + >+ " fSubList = new ArrayList();\n " + >+ " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + >+ " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + >+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 4)\n" + >+ " protected List fList;\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 7)\n" + >+ " protected List fSubList; // raw type warning (good)\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 9)\n" + >+ " fSubList = new ArrayList();\n" + >+ " ^^^^^^^^^\n" + >+ "ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized\n" + >+ "----------\n" + >+ "4. WARNING in X.java (at line 10)\n" + >+ " fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "5. WARNING in X.java (at line 11)\n" + >+ " super.fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "6. WARNING in X.java (at line 12)\n" + >+ " fSubList.add(null); // type safety warning (good, should not be hidden)\n" + >+ " ^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "7. WARNING in X.java (at line 15)\n" + >+ " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + >+ " ^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "8. WARNING in X.java (at line 16)\n" + >+ " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + >+ " ^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "9. WARNING in X.java (at line 17)\n" + >+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "10. WARNING in X.java (at line 20)\n" + >+ " fSubList = new ArrayList();\n" + >+ " ^^^^^^^^^\n" + >+ "ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized\n" + >+ "----------\n" + >+ "11. WARNING in X.java (at line 21)\n" + >+ " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + >+ " ^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "12. WARNING in X.java (at line 22)\n" + >+ " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + >+ " ^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "13. WARNING in X.java (at line 23)\n" + >+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n", >+ null, >+ false, >+ compilerOptions15, >+ null); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=337962 >+public void test337962b() { >+ Map compilerOptions15 = getCompilerOptions(); >+ compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); >+ compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); >+ compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); >+ compilerOptions15.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "import java.util.List;\n" + >+ "import java.util.ArrayList;\n" + >+ "class Super {\n" + >+ " protected List fList;\n" + >+ "}\n" + >+ "public class X extends Super {\n" + >+ " protected List fSubList; // raw type warning (good)\n" + >+ " {\n" + >+ " fSubList = new ArrayList();\n " + >+ " fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" + >+ " super.fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" + >+ " fSubList.add(null); // type safety warning (good, should not be hidden)\n" + >+ " }\n" + >+ " void foo(String s) {\n" + >+ " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + >+ " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + >+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + >+ " }\n" + >+ " X(String s) {\n" + >+ " fSubList = new ArrayList();\n " + >+ " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + >+ " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + >+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 4)\n" + >+ " protected List fList;\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 7)\n" + >+ " protected List fSubList; // raw type warning (good)\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 9)\n" + >+ " fSubList = new ArrayList();\n" + >+ " ^^^^^^^^^\n" + >+ "ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized\n" + >+ "----------\n" + >+ "4. WARNING in X.java (at line 12)\n" + >+ " fSubList.add(null); // type safety warning (good, should not be hidden)\n" + >+ " ^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "5. WARNING in X.java (at line 17)\n" + >+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "6. WARNING in X.java (at line 20)\n" + >+ " fSubList = new ArrayList();\n" + >+ " ^^^^^^^^^\n" + >+ "ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized\n" + >+ "----------\n" + >+ "7. WARNING in X.java (at line 23)\n" + >+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + >+ "----------\n", >+ null, >+ false, >+ compilerOptions15, >+ null); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338011 >+public void test338011() { >+ Map compilerOptions15 = getCompilerOptions(); >+ compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); >+ compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); >+ compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); >+ compilerOptions15.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "import java.util.*;\n" + >+ "public class X extends A {\n" + >+ " public X(Map m) { // should warn about raw type m\n" + >+ " super(m);\n" + >+ " m.put(\"one\", 1); // warns about raw method invocation (good)\n" + >+ " }\n" + >+ " public X(Map<String, Integer> m, boolean b) {\n" + >+ " super(m); // shows that parametrizing the parameter type is no problem \n" + >+ " new A(m);\n" + >+ " m.put(\"one\", 1);\n" + >+ " }\n" + >+ "}\n" + >+ "class A {\n" + >+ " public A (Map m) {\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 3)\n" + >+ " public X(Map m) { // should warn about raw type m\n" + >+ " ^^^\n" + >+ "Map is a raw type. References to generic type Map<K,V> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 5)\n" + >+ " m.put(\"one\", 1); // warns about raw method invocation (good)\n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map<K,V> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 14)\n" + >+ " public A (Map m) {\n" + >+ " ^^^\n" + >+ "Map is a raw type. References to generic type Map<K,V> should be parameterized\n" + >+ "----------\n", >+ null, >+ false, >+ compilerOptions15, >+ null); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338011 >+public void test338011b() { >+ Map compilerOptions15 = getCompilerOptions(); >+ compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); >+ compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); >+ compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); >+ compilerOptions15.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "import java.util.*;\n" + >+ "public class X extends A {\n" + >+ " public X(Map m) { // should warn about raw type m\n" + >+ " super(m);\n" + >+ " m.put(\"one\", 1); // warns about raw method invocation (good)\n" + >+ " }\n" + >+ " public X(Map<String, Integer> m, boolean b) {\n" + >+ " super(m); // shows that parametrizing the parameter type is no problem \n" + >+ " new A(m);\n" + >+ " m.put(\"one\", 1);\n" + >+ " }\n" + >+ "}\n" + >+ "class A {\n" + >+ " public A (Map m) {\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 3)\n" + >+ " public X(Map m) { // should warn about raw type m\n" + >+ " ^^^\n" + >+ "Map is a raw type. References to generic type Map<K,V> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 5)\n" + >+ " m.put(\"one\", 1); // warns about raw method invocation (good)\n" + >+ " ^^^^^^^^^^^^^^^\n" + >+ "Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map<K,V> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 14)\n" + >+ " public A (Map m) {\n" + >+ " ^^^\n" + >+ "Map is a raw type. References to generic type Map<K,V> should be parameterized\n" + >+ "----------\n", >+ null, >+ false, >+ compilerOptions15, >+ null); >+} > } >\ 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 337962
: 191197