### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java,v retrieving revision 1.84 diff -u -r1.84 MethodVerifyTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java 21 Apr 2006 22:11:46 -0000 1.84 +++ src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java 19 May 2006 11:06:34 -0000 @@ -5057,4 +5057,42 @@ "----------\n" ); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation + public void test088() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "import java.util.*;\n" + + "public class X extends ArrayList implements I,Runnable {\n" + + " \n" + + " void foo() {\n" + + " this.add(new Object());\n" + + " this.add(null);\n" + + " }\n" + + "}\n" + + "interface I extends Collection {\n" + + "}\n" , // =================, // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X extends ArrayList implements I,Runnable {\n" + + " ^\n" + + "The interface Collection cannot be implemented more than once with different arguments: Collection and Collection\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public class X extends ArrayList implements I,Runnable {\n" + + " ^\n" + + "The type X must implement the inherited abstract method Runnable.run()\n" + + "----------\n" + + "3. WARNING in X.java (at line 2)\n" + + " public class X extends ArrayList implements I,Runnable {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " this.add(new Object());\n" + + " ^^^\n" + + "The method add(T0) in the type ArrayList is not applicable for the arguments (Object)\n" + + "----------\n"); + } } 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.492 diff -u -r1.492 GenericTypeTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 18 May 2006 15:28:25 -0000 1.492 +++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 19 May 2006 11:06:31 -0000 @@ -31228,4 +31228,110 @@ "The return type is incompatible with AbstractEditPart.getViewer()\n" + "----------\n"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 +public void test0989() { + this.runNegativeTest( + new String[] { + "Child.java",//=================== + "public class Child extends Parent {}\n" + + "abstract class Parent extends Grandparent implements IParent {}\n" + + "interface IParent extends IGrandparent {}\n" + + "abstract class Grandparent implements IGrandparent {}\n" + + "interface IGrandparent {}", // =================, // ================= + }, + "----------\n" + + "1. ERROR in Child.java (at line 2)\n" + + " abstract class Parent extends Grandparent implements IParent {}\n" + + " ^^^^^^\n" + + "The interface IGrandparent cannot be implemented more than once with different arguments: IGrandparent and IGrandparent\n" + + "----------\n" + + "2. WARNING in Child.java (at line 2)\n" + + " abstract class Parent extends Grandparent implements IParent {}\n" + + " ^^^^^^^\n" + + "IParent is a raw type. References to generic type IParent should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation +public void test0990() { + this.runNegativeTest( + new String[] { + "Child.java",//=================== + "public class Child extends Parent {}\n" + + "abstract class Parent extends Grandparent implements IParent {}\n" + + "interface IParent extends IGrandparent {}\n" + + "abstract class Grandparent implements IGrandparent {}\n" + + "interface IGrandparent {}", // =================, // ================= + }, + "----------\n" + + "1. ERROR in Child.java (at line 1)\n" + + " public class Child extends Parent {}\n" + + " ^^^^^\n" + + "The hierarchy of the type Child is inconsistent\n" + + "----------\n" + + "2. ERROR in Child.java (at line 2)\n" + + " abstract class Parent extends Grandparent implements IParent {}\n" + + " ^^^^^^^\n" + + "The type Parent cannot extend or implement IParent. A supertype may not specify any wildcard\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation +public void test0991() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "public class X extends SX implements IX {}\n" + + "class SX extends TX implements IX {}\n" + + "class TX implements IX {}\n" + + "interface IX {}\n", // =================, // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends SX implements IX {}\n" + + " ^\n" + + "The interface IX cannot be implemented more than once with different arguments: IX and IX\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " class SX extends TX implements IX {}\n" + + " ^^\n" + + "The interface IX cannot be implemented more than once with different arguments: IX and IX\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation +public void test0992() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "import java.util.*;\n" + + "public abstract class X implements Collection, I {\n" + + " \n" + + " void foo() {\n" + + " this.add(new Object());\n" + + " this.add(null);\n" + + " }\n" + + "}\n" + + "interface I extends Collection {\n" + + "}\n", // =================, // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public abstract class X implements Collection, I {\n" + + " ^\n" + + "The interface Collection cannot be implemented more than once with different arguments: Collection and Collection\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " public abstract class X implements Collection, I {\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " this.add(new Object());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type Collection. References to generic type Collection should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " this.add(null);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type Collection. References to generic type Collection should be parameterized\n" + + "----------\n"); +} } #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java,v retrieving revision 1.100 diff -u -r1.100 CompilationUnitScope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java 14 Apr 2006 08:34:05 -0000 1.100 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java 19 May 2006 11:06:38 -0000 @@ -202,7 +202,6 @@ for (int i = 0, length = topLevelTypes.length; i < length; i++) { ClassScope scope = topLevelTypes[i].scope; scope.checkParameterizedTypeBounds(); - scope.checkParameterizedSuperTypeCollisions(); } } /* Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java,v retrieving revision 1.136 diff -u -r1.136 ClassScope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java 28 Apr 2006 14:53:28 -0000 1.136 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java 19 May 2006 11:06:37 -0000 @@ -621,40 +621,52 @@ fieldBinding.modifiers = modifiers; } - public void checkParameterizedSuperTypeCollisions() { - // check for parameterized interface collisions (when different parameterizations occur) + /** + * Check for super type collisions (both superinterfaces and type variables). + * @return the list of non-colliding superinterfaces + */ + public ReferenceBinding[] computeNonCollidingSuperInterfaces() { SourceTypeBinding sourceType = referenceContext.binding; - ReferenceBinding[] interfaces = sourceType.superInterfaces; - int count = interfaces.length; + if (compilerOptions().sourceLevel < ClassFileConstants.JDK1_5) return sourceType.superInterfaces; + ReferenceBinding[] nonCollidingSuperInterfaces = sourceType.superInterfaces; // lazy allocation of clone if problem is discovered + int count = nonCollidingSuperInterfaces.length; Map invocations = new HashMap(2); ReferenceBinding itsSuperclass = sourceType.isInterface() ? null : sourceType.superclass; + + // check for parameterized interface collisions (when different parameterizations occur) nextInterface: for (int i = 0, length = count; i < length; i++) { - ReferenceBinding one = interfaces[i]; + ReferenceBinding one = nonCollidingSuperInterfaces[i]; if (one == null) continue nextInterface; if (itsSuperclass != null && hasErasedCandidatesCollisions(itsSuperclass, one, invocations, sourceType, referenceContext)) { - interfaces[i] = null; + if (nonCollidingSuperInterfaces == sourceType.superInterfaces) { // lazy cloning + System.arraycopy(sourceType.superInterfaces, 0, nonCollidingSuperInterfaces = new ReferenceBinding[count], 0, count); + } + nonCollidingSuperInterfaces[i] = null; count--; continue nextInterface; } nextOtherInterface: for (int j = 0; j < i; j++) { - ReferenceBinding two = interfaces[j]; + ReferenceBinding two = nonCollidingSuperInterfaces[j]; if (two == null) continue nextOtherInterface; if (hasErasedCandidatesCollisions(one, two, invocations, sourceType, referenceContext)) { - interfaces[i] = null; + if (nonCollidingSuperInterfaces == sourceType.superInterfaces) { // lazy cloning + System.arraycopy(sourceType.superInterfaces, 0, nonCollidingSuperInterfaces = new ReferenceBinding[count], 0, count); + } + nonCollidingSuperInterfaces[i] = null; count--; continue nextInterface; } } } - if (count < interfaces.length) { + if (count < nonCollidingSuperInterfaces.length) { if (count == 0) { - sourceType.superInterfaces = Binding.NO_SUPERINTERFACES; + nonCollidingSuperInterfaces = Binding.NO_SUPERINTERFACES; } else { ReferenceBinding[] newInterfaceBindings = new ReferenceBinding[count]; - for (int i = 0, j = 0, l = interfaces.length; i < l; i++) - if (interfaces[i] != null) - newInterfaceBindings[j++] = interfaces[i]; - sourceType.superInterfaces = newInterfaceBindings; + for (int i = 0, j = 0, l = nonCollidingSuperInterfaces.length; i < l; i++) + if (nonCollidingSuperInterfaces[i] != null) + newInterfaceBindings[j++] = nonCollidingSuperInterfaces[i]; + nonCollidingSuperInterfaces = newInterfaceBindings; } } @@ -683,11 +695,7 @@ } } } - - ReferenceBinding[] memberTypes = referenceContext.binding.memberTypes; - if (memberTypes != null && memberTypes != Binding.NO_MEMBER_TYPES) - for (int i = 0, size = memberTypes.length; i < size; i++) - ((SourceTypeBinding) memberTypes[i]).scope.checkParameterizedSuperTypeCollisions(); + return nonCollidingSuperInterfaces; } private void checkForInheritedMemberTypes(SourceTypeBinding sourceType) { Index: compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java,v retrieving revision 1.78 diff -u -r1.78 MethodVerifier.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java 2 May 2006 19:46:54 -0000 1.78 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java 19 May 2006 11:06:38 -0000 @@ -389,7 +389,8 @@ ReferenceBinding superclass = this.type.isInterface() ? this.type.scope.getJavaLangObject() // check interface methods against Object : this.type.superclass(); // class or enum - computeInheritedMethods(superclass, type.superInterfaces()); + ReferenceBinding[] interfaces = this.type.scope.computeNonCollidingSuperInterfaces(); + computeInheritedMethods(superclass, interfaces); } /* Binding creation is responsible for reporting: