View | Details | Raw Unified | Return to bug 142653 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java (+38 lines)
Lines 5057-5060 Link Here
5057
			"----------\n"
5057
			"----------\n"
5058
		);
5058
		);
5059
	}	
5059
	}	
5060
//	https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation
5061
	public void test088() {
5062
		this.runNegativeTest(
5063
				new String[] {
5064
					"X.java",//===================
5065
					"import java.util.*;\n" +
5066
					"public class X<T0> extends ArrayList<T0> implements I<T0>,Runnable {\n" + 
5067
					"	\n" + 
5068
					"	void foo() {\n" + 
5069
					"		this.add(new Object());\n" + 
5070
					"		this.add(null);\n" + 
5071
					"	}\n" + 
5072
					"}\n" + 
5073
					"interface I<T1> extends Collection<String> {\n" + 
5074
					"}\n" , // =================, // =================			
5075
				},
5076
				"----------\n" + 
5077
				"1. ERROR in X.java (at line 2)\n" + 
5078
				"	public class X<T0> extends ArrayList<T0> implements I<T0>,Runnable {\n" + 
5079
				"	             ^\n" + 
5080
				"The interface Collection cannot be implemented more than once with different arguments: Collection<T0> and Collection<String>\n" + 
5081
				"----------\n" + 
5082
				"2. ERROR in X.java (at line 2)\n" + 
5083
				"	public class X<T0> extends ArrayList<T0> implements I<T0>,Runnable {\n" + 
5084
				"	             ^\n" + 
5085
				"The type X<T0> must implement the inherited abstract method Runnable.run()\n" + 
5086
				"----------\n" + 
5087
				"3. WARNING in X.java (at line 2)\n" + 
5088
				"	public class X<T0> extends ArrayList<T0> implements I<T0>,Runnable {\n" + 
5089
				"	             ^\n" + 
5090
				"The serializable class X does not declare a static final serialVersionUID field of type long\n" + 
5091
				"----------\n" + 
5092
				"4. ERROR in X.java (at line 5)\n" + 
5093
				"	this.add(new Object());\n" + 
5094
				"	     ^^^\n" + 
5095
				"The method add(T0) in the type ArrayList<T0> is not applicable for the arguments (Object)\n" + 
5096
				"----------\n");
5097
	}	
5060
}
5098
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (+106 lines)
Lines 31228-31231 Link Here
31228
			"The return type is incompatible with AbstractEditPart.getViewer()\n" + 
31228
			"The return type is incompatible with AbstractEditPart.getViewer()\n" + 
31229
			"----------\n");
31229
			"----------\n");
31230
}
31230
}
31231
//	https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653
31232
public void test0989() {
31233
	this.runNegativeTest(
31234
			new String[] {
31235
				"Child.java",//===================
31236
				"public class Child extends Parent<Object> {}\n" + 
31237
				"abstract class Parent<T> extends Grandparent<T> implements IParent {}\n" + 
31238
				"interface IParent<T> extends IGrandparent<T> {}\n" + 
31239
				"abstract class Grandparent<T> implements IGrandparent<T> {}\n" + 
31240
				"interface IGrandparent<T> {}", // =================, // =================			
31241
			},
31242
			"----------\n" + 
31243
			"1. ERROR in Child.java (at line 2)\n" + 
31244
			"	abstract class Parent<T> extends Grandparent<T> implements IParent {}\n" + 
31245
			"	               ^^^^^^\n" + 
31246
			"The interface IGrandparent cannot be implemented more than once with different arguments: IGrandparent<T> and IGrandparent\n" + 
31247
			"----------\n" + 
31248
			"2. WARNING in Child.java (at line 2)\n" + 
31249
			"	abstract class Parent<T> extends Grandparent<T> implements IParent {}\n" + 
31250
			"	                                                           ^^^^^^^\n" + 
31251
			"IParent is a raw type. References to generic type IParent<T> should be parameterized\n" + 
31252
			"----------\n");
31253
}
31254
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation
31255
public void test0990() {
31256
	this.runNegativeTest(
31257
			new String[] {
31258
				"Child.java",//===================
31259
				"public class Child extends Parent<Object> {}\n" + 
31260
				"abstract class Parent<T> extends Grandparent<T> implements IParent<?> {}\n" + 
31261
				"interface IParent<T> extends IGrandparent<T> {}\n" + 
31262
				"abstract class Grandparent<T> implements IGrandparent<T> {}\n" + 
31263
				"interface IGrandparent<T> {}", // =================, // =================			
31264
			},
31265
			"----------\n" + 
31266
			"1. ERROR in Child.java (at line 1)\n" + 
31267
			"	public class Child extends Parent<Object> {}\n" + 
31268
			"	             ^^^^^\n" + 
31269
			"The hierarchy of the type Child is inconsistent\n" + 
31270
			"----------\n" + 
31271
			"2. ERROR in Child.java (at line 2)\n" + 
31272
			"	abstract class Parent<T> extends Grandparent<T> implements IParent<?> {}\n" + 
31273
			"	                                                           ^^^^^^^\n" + 
31274
			"The type Parent cannot extend or implement IParent<?>. A supertype may not specify any wildcard\n" + 
31275
			"----------\n");
31276
}
31277
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation
31278
public void test0991() {
31279
	this.runNegativeTest(
31280
			new String[] {
31281
				"X.java",//===================
31282
				"public class X extends SX<String> implements IX<Object> {}\n" + 
31283
				"class SX<T> extends TX<Thread> implements IX<T> {}\n" + 
31284
				"class TX<U> implements IX<U> {}\n" + 
31285
				"interface IX<V> {}\n", // =================, // =================			
31286
			},
31287
			"----------\n" + 
31288
			"1. ERROR in X.java (at line 1)\n" + 
31289
			"	public class X extends SX<String> implements IX<Object> {}\n" + 
31290
			"	             ^\n" + 
31291
			"The interface IX cannot be implemented more than once with different arguments: IX<Thread> and IX<Object>\n" + 
31292
			"----------\n" + 
31293
			"2. ERROR in X.java (at line 2)\n" + 
31294
			"	class SX<T> extends TX<Thread> implements IX<T> {}\n" + 
31295
			"	      ^^\n" + 
31296
			"The interface IX cannot be implemented more than once with different arguments: IX<Thread> and IX<T>\n" + 
31297
			"----------\n");
31298
}
31299
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation
31300
public void test0992() {
31301
	this.runNegativeTest(
31302
			new String[] {
31303
				"X.java",//===================
31304
				"import java.util.*;\n" + 
31305
				"public abstract class X<T0> implements Collection, I<T0> {\n" + 
31306
				"	\n" + 
31307
				"	void foo() {\n" + 
31308
				"		this.add(new Object());\n" + 
31309
				"		this.add(null);\n" + 
31310
				"	}\n" + 
31311
				"}\n" + 
31312
				"interface I<T1> extends Collection<String> {\n" + 
31313
				"}\n", // =================, // =================			
31314
			},
31315
			"----------\n" + 
31316
			"1. ERROR in X.java (at line 2)\n" + 
31317
			"	public abstract class X<T0> implements Collection, I<T0> {\n" + 
31318
			"	                      ^\n" + 
31319
			"The interface Collection cannot be implemented more than once with different arguments: Collection<String> and Collection\n" + 
31320
			"----------\n" + 
31321
			"2. WARNING in X.java (at line 2)\n" + 
31322
			"	public abstract class X<T0> implements Collection, I<T0> {\n" + 
31323
			"	                                       ^^^^^^^^^^\n" + 
31324
			"Collection is a raw type. References to generic type Collection<E> should be parameterized\n" + 
31325
			"----------\n" + 
31326
			"3. WARNING in X.java (at line 5)\n" + 
31327
			"	this.add(new Object());\n" + 
31328
			"	^^^^^^^^^^^^^^^^^^^^^^\n" + 
31329
			"Type safety: The method add(Object) belongs to the raw type Collection. References to generic type Collection<E> should be parameterized\n" + 
31330
			"----------\n" + 
31331
			"4. WARNING in X.java (at line 6)\n" + 
31332
			"	this.add(null);\n" + 
31333
			"	^^^^^^^^^^^^^^\n" + 
31334
			"Type safety: The method add(Object) belongs to the raw type Collection. References to generic type Collection<E> should be parameterized\n" + 
31335
			"----------\n");
31336
}
31231
}
31337
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java (-1 lines)
Lines 202-208 Link Here
202
	for (int i = 0, length = topLevelTypes.length; i < length; i++) {
202
	for (int i = 0, length = topLevelTypes.length; i < length; i++) {
203
		ClassScope scope = topLevelTypes[i].scope;
203
		ClassScope scope = topLevelTypes[i].scope;
204
		scope.checkParameterizedTypeBounds();
204
		scope.checkParameterizedTypeBounds();
205
		scope.checkParameterizedSuperTypeCollisions();
206
	}
205
	}
207
}
206
}
208
/*
207
/*
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java (-19 / +27 lines)
Lines 621-660 Link Here
621
		fieldBinding.modifiers = modifiers;
621
		fieldBinding.modifiers = modifiers;
622
	}
622
	}
623
623
624
	public void checkParameterizedSuperTypeCollisions() {
624
	/**
625
		// check for parameterized interface collisions (when different parameterizations occur)
625
	 * Check for super type collisions (both superinterfaces and type variables).
626
	 * @return the list of non-colliding superinterfaces
627
	 */	
628
	public ReferenceBinding[] computeNonCollidingSuperInterfaces() {
626
		SourceTypeBinding sourceType = referenceContext.binding;
629
		SourceTypeBinding sourceType = referenceContext.binding;
627
		ReferenceBinding[] interfaces = sourceType.superInterfaces;
630
		if (compilerOptions().sourceLevel < ClassFileConstants.JDK1_5) return sourceType.superInterfaces;
628
		int count = interfaces.length;
631
		ReferenceBinding[] nonCollidingSuperInterfaces = sourceType.superInterfaces; // lazy allocation of clone if problem is discovered
632
		int count = nonCollidingSuperInterfaces.length;
629
		Map invocations = new HashMap(2);
633
		Map invocations = new HashMap(2);
630
		ReferenceBinding itsSuperclass = sourceType.isInterface() ? null : sourceType.superclass;
634
		ReferenceBinding itsSuperclass = sourceType.isInterface() ? null : sourceType.superclass;
635
636
		// check for parameterized interface collisions (when different parameterizations occur)
631
		nextInterface: for (int i = 0, length = count; i < length; i++) {
637
		nextInterface: for (int i = 0, length = count; i < length; i++) {
632
			ReferenceBinding one =  interfaces[i];
638
			ReferenceBinding one =  nonCollidingSuperInterfaces[i];
633
			if (one == null) continue nextInterface;
639
			if (one == null) continue nextInterface;
634
			if (itsSuperclass != null && hasErasedCandidatesCollisions(itsSuperclass, one, invocations, sourceType, referenceContext)) {
640
			if (itsSuperclass != null && hasErasedCandidatesCollisions(itsSuperclass, one, invocations, sourceType, referenceContext)) {
635
				interfaces[i] = null;
641
				if (nonCollidingSuperInterfaces == sourceType.superInterfaces) { // lazy cloning
642
					System.arraycopy(sourceType.superInterfaces, 0, nonCollidingSuperInterfaces = new ReferenceBinding[count], 0, count);
643
				}
644
				nonCollidingSuperInterfaces[i] = null;
636
				count--;
645
				count--;
637
				continue nextInterface;
646
				continue nextInterface;
638
			}
647
			}
639
			nextOtherInterface: for (int j = 0; j < i; j++) {
648
			nextOtherInterface: for (int j = 0; j < i; j++) {
640
				ReferenceBinding two = interfaces[j];
649
				ReferenceBinding two = nonCollidingSuperInterfaces[j];
641
				if (two == null) continue nextOtherInterface;
650
				if (two == null) continue nextOtherInterface;
642
				if (hasErasedCandidatesCollisions(one, two, invocations, sourceType, referenceContext)) {
651
				if (hasErasedCandidatesCollisions(one, two, invocations, sourceType, referenceContext)) {
643
					interfaces[i] = null;
652
					if (nonCollidingSuperInterfaces == sourceType.superInterfaces) { // lazy cloning
653
						System.arraycopy(sourceType.superInterfaces, 0, nonCollidingSuperInterfaces = new ReferenceBinding[count], 0, count);
654
					}
655
					nonCollidingSuperInterfaces[i] = null;
644
					count--;
656
					count--;
645
					continue nextInterface;
657
					continue nextInterface;
646
				}
658
				}
647
			}
659
			}
648
		}
660
		}
649
		if (count < interfaces.length) {
661
		if (count < nonCollidingSuperInterfaces.length) {
650
			if (count == 0) {
662
			if (count == 0) {
651
				sourceType.superInterfaces = Binding.NO_SUPERINTERFACES;
663
				nonCollidingSuperInterfaces = Binding.NO_SUPERINTERFACES;
652
			} else {
664
			} else {
653
				ReferenceBinding[] newInterfaceBindings = new ReferenceBinding[count];
665
				ReferenceBinding[] newInterfaceBindings = new ReferenceBinding[count];
654
				for (int i = 0, j = 0, l = interfaces.length; i < l; i++)
666
				for (int i = 0, j = 0, l = nonCollidingSuperInterfaces.length; i < l; i++)
655
					if (interfaces[i] != null)
667
					if (nonCollidingSuperInterfaces[i] != null)
656
						newInterfaceBindings[j++] = interfaces[i];
668
						newInterfaceBindings[j++] = nonCollidingSuperInterfaces[i];
657
				sourceType.superInterfaces = newInterfaceBindings;
669
				nonCollidingSuperInterfaces = newInterfaceBindings;
658
			}
670
			}
659
		}
671
		}
660
672
Lines 683-693 Link Here
683
				}
695
				}
684
			}
696
			}
685
		}
697
		}
686
698
		return nonCollidingSuperInterfaces;
687
		ReferenceBinding[] memberTypes = referenceContext.binding.memberTypes;
688
		if (memberTypes != null && memberTypes != Binding.NO_MEMBER_TYPES)
689
			for (int i = 0, size = memberTypes.length; i < size; i++)
690
				 ((SourceTypeBinding) memberTypes[i]).scope.checkParameterizedSuperTypeCollisions();
691
	}
699
	}
692
700
693
	private void checkForInheritedMemberTypes(SourceTypeBinding sourceType) {
701
	private void checkForInheritedMemberTypes(SourceTypeBinding sourceType) {
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java (-1 / +2 lines)
Lines 389-395 Link Here
389
	ReferenceBinding superclass = this.type.isInterface()
389
	ReferenceBinding superclass = this.type.isInterface()
390
		? this.type.scope.getJavaLangObject() // check interface methods against Object
390
		? this.type.scope.getJavaLangObject() // check interface methods against Object
391
		: this.type.superclass(); // class or enum
391
		: this.type.superclass(); // class or enum
392
	computeInheritedMethods(superclass, type.superInterfaces());
392
	ReferenceBinding[] interfaces = this.type.scope.computeNonCollidingSuperInterfaces();
393
	computeInheritedMethods(superclass, interfaces);
393
}
394
}
394
/*
395
/*
395
Binding creation is responsible for reporting:
396
Binding creation is responsible for reporting:

Return to bug 142653