View | Details | Raw Unified | Return to bug 298362
Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java (-1 / +4 lines)
Lines 130-137 Link Here
130
				problemReporter().unsafeReturnTypeOverride(concreteMethod, originalInherited, this.type);
130
				problemReporter().unsafeReturnTypeOverride(concreteMethod, originalInherited, this.type);
131
131
132
		// check whether bridge method is already defined above for interface methods
132
		// check whether bridge method is already defined above for interface methods
133
		// skip generation of bridge method for current class & method if an equivalent
134
		// bridge will be/would have been generated in the context of the super class since
135
		// the bridge itself will be inherited. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=298362
133
		if (originalInherited.declaringClass.isInterface()) {
136
		if (originalInherited.declaringClass.isInterface()) {
134
			if ((concreteMethod.declaringClass == this.type.superclass && this.type.superclass.isParameterizedType())
137
			if ((concreteMethod.declaringClass == this.type.superclass && this.type.superclass.isParameterizedType() && !areMethodsCompatible(concreteMethod, originalInherited))
135
				|| this.type.superclass.erasure().findSuperTypeOriginatingFrom(originalInherited.declaringClass) == null)
138
				|| this.type.superclass.erasure().findSuperTypeOriginatingFrom(originalInherited.declaringClass) == null)
136
					this.type.addSyntheticBridgeMethod(originalInherited, concreteMethod.original());
139
					this.type.addSyntheticBridgeMethod(originalInherited, concreteMethod.original());
137
		}
140
		}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java (+97 lines)
Lines 10731-10734 Link Here
10731
		"Name clash: The method put(K, V) of type OverrideBug<K,V> has the same erasure as put(K, V) of type Map<K,V> but does not override it\n" + 
10731
		"Name clash: The method put(K, V) of type OverrideBug<K,V> has the same erasure as put(K, V) of type Map<K,V> but does not override it\n" + 
10732
		"----------\n");
10732
		"----------\n");
10733
}
10733
}
10734
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=298362
10735
public void test205() {
10736
	this.runConformTest(
10737
		new String[] {
10738
			"Tester.java",
10739
			"import java.lang.reflect.Method;\n" +
10740
			"\n" +
10741
			"public class Tester {\n" +
10742
			"\n" +
10743
			" public static interface Converter<T> {\n" +
10744
			"   T convert(String input);\n" +
10745
			" }\n" +
10746
			"\n" +
10747
			" public static abstract class EnumConverter<T extends Enum<T>> implements Converter<Enum<T>> {\n" +
10748
			"   public final T convert(String input) {\n" +
10749
			"     return null;\n" +
10750
			"   }\n" +
10751
			" }\n" +
10752
			"\n" +
10753
			" public static class SomeEnumConverter extends EnumConverter<Thread.State> {\n" +
10754
			" }\n" +
10755
			"\n" +
10756
			" public static void main(String[] args) throws Exception {\n" +
10757
			"   Method m = SomeEnumConverter.class.getMethod(\"convert\", String.class);\n" +
10758
			"   System.out.println(m.getGenericReturnType());\n" +
10759
			" }\n" +
10760
			"\n" +
10761
			"}\n"
10762
10763
		},
10764
		"T");
10765
}
10766
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=298362 (variation)
10767
public void test206() {
10768
	this.runConformTest(
10769
		new String[] {
10770
			"Tester.java",
10771
			"import java.lang.reflect.Method;\n" +
10772
			"\n" +
10773
			"public class Tester {\n" +
10774
			"\n" +
10775
			" public static interface Converter<T> {\n" +
10776
			"   T convert(String input);\n" +
10777
			" }\n" +
10778
			"\n" +
10779
			" public static abstract class EnumConverter<T extends Enum<T>> implements Converter<T> {\n" +
10780
			"   public final T convert(String input) {\n" +
10781
			"     return null;\n" +
10782
			"   }\n" +
10783
			" }\n" +
10784
			"\n" +
10785
			" public static class SomeEnumConverter extends EnumConverter<Thread.State> {\n" +
10786
			" }\n" +
10787
			"\n" +
10788
			" public static void main(String[] args) throws Exception {\n" +
10789
			"   Method m = SomeEnumConverter.class.getMethod(\"convert\", String.class);\n" +
10790
			"   System.out.println(m.getGenericReturnType());\n" +
10791
			" }\n" +
10792
			"\n" +
10793
			"}\n"
10794
10795
		},
10796
		"T");
10797
}
10798
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=298362 (variation)
10799
// Note that this test prints "T" with javac5 and "class java.lang.Object with javac 6,7
10800
public void test207() {
10801
	this.runConformTest(
10802
		new String[] {
10803
			"Tester.java",
10804
			"import java.lang.reflect.Method;\n" +
10805
			"\n" +
10806
			"public class Tester {\n" +
10807
			"\n" +
10808
			" public static interface Converter<T> {\n" +
10809
			"   T convert(String input);\n" +
10810
			" }\n" +
10811
			"\n" +
10812
			" public static abstract class EnumConverter<T extends Enum<T>, K> implements Converter<T> {\n" +
10813
			"   public final T convert(K input) {\n" +
10814
			"     return null;\n" +
10815
			"   }\n" +
10816
			" }\n" +
10817
			"\n" +
10818
			" public static class SomeEnumConverter extends EnumConverter<Thread.State, String> {\n" +
10819
			" }\n" +
10820
			"\n" +
10821
			" public static void main(String[] args) throws Exception {\n" +
10822
			"   Method m = SomeEnumConverter.class.getMethod(\"convert\", String.class);\n" +
10823
			"   System.out.println(m.getGenericReturnType());\n" +
10824
			" }\n" +
10825
			"\n" +
10826
			"}\n"
10827
10828
		},
10829
		"class java.lang.Object");
10830
}
10734
}
10831
}

Return to bug 298362