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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java (+66 lines)
Lines 11-16 Link Here
11
package org.eclipse.jdt.internal.compiler.lookup;
11
package org.eclipse.jdt.internal.compiler.lookup;
12
12
13
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
13
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
14
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
14
15
15
class MethodVerifier15 extends MethodVerifier {
16
class MethodVerifier15 extends MethodVerifier {
16
17
Lines 528-533 Link Here
528
		&& inheritedMethod.returnType == existingMethod.returnType
529
		&& inheritedMethod.returnType == existingMethod.returnType
529
		&& super.isInterfaceMethodImplemented(inheritedMethod, existingMethod, superType);
530
		&& super.isInterfaceMethodImplemented(inheritedMethod, existingMethod, superType);
530
}
531
}
532
SimpleSet findSuperinterfaceCollisions(ReferenceBinding superclass, ReferenceBinding[] superInterfaces) {
533
	ReferenceBinding[] interfacesToVisit = null;
534
	int nextPosition = 0;
535
	ReferenceBinding[] itsInterfaces = superInterfaces;
536
	if (itsInterfaces != Binding.NO_SUPERINTERFACES) {
537
		nextPosition = itsInterfaces.length;
538
		interfacesToVisit = itsInterfaces;
539
	}
540
541
	ReferenceBinding superType = superclass;
542
	while (superType != null && superType.isValidBinding()) {
543
		if ((itsInterfaces = superType.superInterfaces()) != Binding.NO_SUPERINTERFACES) {
544
			if (interfacesToVisit == null) {
545
				interfacesToVisit = itsInterfaces;
546
				nextPosition = interfacesToVisit.length;
547
			} else {
548
				int itsLength = itsInterfaces.length;
549
				if (nextPosition + itsLength >= interfacesToVisit.length)
550
					System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition);
551
				nextInterface : for (int a = 0; a < itsLength; a++) {
552
					ReferenceBinding next = itsInterfaces[a];
553
					for (int b = 0; b < nextPosition; b++)
554
						if (next == interfacesToVisit[b]) continue nextInterface;
555
					interfacesToVisit[nextPosition++] = next;
556
				}
557
			}
558
		}
559
		superType = superType.superclass();
560
	}
561
562
	for (int i = 0; i < nextPosition; i++) {
563
		superType = interfacesToVisit[i];
564
		if (superType.isValidBinding()) {
565
			if ((itsInterfaces = superType.superInterfaces()) != Binding.NO_SUPERINTERFACES) {
566
				int itsLength = itsInterfaces.length;
567
				if (nextPosition + itsLength >= interfacesToVisit.length)
568
					System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition);
569
				nextInterface : for (int a = 0; a < itsLength; a++) {
570
					ReferenceBinding next = itsInterfaces[a];
571
					for (int b = 0; b < nextPosition; b++)
572
						if (next == interfacesToVisit[b]) continue nextInterface;
573
					interfacesToVisit[nextPosition++] = next;
574
				}
575
			}
576
		}
577
	}
578
579
	SimpleSet copy = null;
580
	for (int i = 0; i < nextPosition; i++) {
581
		ReferenceBinding current = interfacesToVisit[i];
582
		if (current.isValidBinding()) {
583
			TypeBinding erasure = current.erasure();
584
			for (int j = i + 1; j < nextPosition; j++) {
585
				ReferenceBinding next = interfacesToVisit[j];
586
				if (next.isValidBinding() && next.erasure() == erasure) {
587
					if (copy == null)
588
						copy = new SimpleSet(nextPosition);
589
					copy.add(interfacesToVisit[i]);
590
					copy.add(interfacesToVisit[j]);
591
				}
592
			}
593
		}
594
	}
595
	return copy;
596
}
531
boolean reportIncompatibleReturnTypeError(MethodBinding currentMethod, MethodBinding inheritedMethod) {
597
boolean reportIncompatibleReturnTypeError(MethodBinding currentMethod, MethodBinding inheritedMethod) {
532
	if (currentMethod.typeVariables == Binding.NO_TYPE_VARIABLES
598
	if (currentMethod.typeVariables == Binding.NO_TYPE_VARIABLES
533
		&& inheritedMethod.original().typeVariables != Binding.NO_TYPE_VARIABLES
599
		&& inheritedMethod.original().typeVariables != Binding.NO_TYPE_VARIABLES
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java (-21 / +3 lines)
Lines 625-660 Link Here
625
		// check for parameterized interface collisions (when different parameterizations occur)
625
		// check for parameterized interface collisions (when different parameterizations occur)
626
		SourceTypeBinding sourceType = referenceContext.binding;
626
		SourceTypeBinding sourceType = referenceContext.binding;
627
		ReferenceBinding[] interfaces = sourceType.superInterfaces;
627
		ReferenceBinding[] interfaces = sourceType.superInterfaces;
628
		int count = interfaces.length;
629
		Map invocations = new HashMap(2);
628
		Map invocations = new HashMap(2);
630
		ReferenceBinding itsSuperclass = sourceType.isInterface() ? null : sourceType.superclass;
629
		ReferenceBinding itsSuperclass = sourceType.isInterface() ? null : sourceType.superclass;
631
		nextInterface: for (int i = 0, length = count; i < length; i++) {
630
		nextInterface: for (int i = 0, length = interfaces.length; i < length; i++) {
632
			ReferenceBinding one =  interfaces[i];
631
			ReferenceBinding one =  interfaces[i];
633
			if (one == null) continue nextInterface;
632
			if (one == null) continue nextInterface;
634
			if (itsSuperclass != null && hasErasedCandidatesCollisions(itsSuperclass, one, invocations, sourceType, referenceContext)) {
633
			if (itsSuperclass != null && hasErasedCandidatesCollisions(itsSuperclass, one, invocations, sourceType, referenceContext))
635
				interfaces[i] = null;
636
				count--;
637
				continue nextInterface;
634
				continue nextInterface;
638
			}
639
			nextOtherInterface: for (int j = 0; j < i; j++) {
635
			nextOtherInterface: for (int j = 0; j < i; j++) {
640
				ReferenceBinding two = interfaces[j];
636
				ReferenceBinding two = interfaces[j];
641
				if (two == null) continue nextOtherInterface;
637
				if (two == null) continue nextOtherInterface;
642
				if (hasErasedCandidatesCollisions(one, two, invocations, sourceType, referenceContext)) {
638
				if (hasErasedCandidatesCollisions(one, two, invocations, sourceType, referenceContext))
643
					interfaces[i] = null;
644
					count--;
645
					continue nextInterface;
639
					continue nextInterface;
646
				}
647
			}
648
		}
649
		if (count < interfaces.length) {
650
			if (count == 0) {
651
				sourceType.superInterfaces = Binding.NO_SUPERINTERFACES;
652
			} else {
653
				ReferenceBinding[] newInterfaceBindings = new ReferenceBinding[count];
654
				for (int i = 0, j = 0, l = interfaces.length; i < l; i++)
655
					if (interfaces[i] != null)
656
						newInterfaceBindings[j++] = interfaces[i];
657
				sourceType.superInterfaces = newInterfaceBindings;
658
			}
640
			}
659
		}
641
		}
660
642
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java (+7 lines)
Lines 16-21 Link Here
16
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
16
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
17
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
17
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
18
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
18
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
19
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
19
20
20
public class MethodVerifier {
21
public class MethodVerifier {
21
	SourceTypeBinding type;
22
	SourceTypeBinding type;
Lines 501-510 Link Here
501
		}
502
		}
502
		superType = superType.superclass();
503
		superType = superType.superclass();
503
	}
504
	}
505
	if (nextPosition == 0) return;
504
506
507
	SimpleSet skip = findSuperinterfaceCollisions(superclass, superInterfaces);
505
	for (int i = 0; i < nextPosition; i++) {
508
	for (int i = 0; i < nextPosition; i++) {
506
		superType = interfacesToVisit[i];
509
		superType = interfacesToVisit[i];
507
		if (superType.isValidBinding()) {
510
		if (superType.isValidBinding()) {
511
			if (skip != null && skip.includes(superType)) continue;
508
			if ((itsInterfaces = superType.superInterfaces()) != Binding.NO_SUPERINTERFACES) {
512
			if ((itsInterfaces = superType.superInterfaces()) != Binding.NO_SUPERINTERFACES) {
509
				int itsLength = itsInterfaces.length;
513
				int itsLength = itsInterfaces.length;
510
				if (nextPosition + itsLength >= interfacesToVisit.length)
514
				if (nextPosition + itsLength >= interfacesToVisit.length)
Lines 614-619 Link Here
614
		reporter.referenceContext = currentMethod.sourceMethod();
618
		reporter.referenceContext = currentMethod.sourceMethod();
615
	return reporter;
619
	return reporter;
616
}
620
}
621
SimpleSet findSuperinterfaceCollisions(ReferenceBinding superclass, ReferenceBinding[] superInterfaces) {
622
	return null; // noop in 1.4
623
}
617
boolean reportIncompatibleReturnTypeError(MethodBinding currentMethod, MethodBinding inheritedMethod) {
624
boolean reportIncompatibleReturnTypeError(MethodBinding currentMethod, MethodBinding inheritedMethod) {
618
	problemReporter(currentMethod).incompatibleReturnType(currentMethod, inheritedMethod);
625
	problemReporter(currentMethod).incompatibleReturnType(currentMethod, inheritedMethod);
619
	return true;
626
	return true;
(-)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
}

Return to bug 142653