Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 456012

Summary: No compiler error from implementing clashing generic interfaces if implementations of clashing methods are inherited
Product: [Eclipse Project] JDT Reporter: Theodore Murdock <theodoremurdock>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: CLOSED INVALID QA Contact: Sasikanth Bharadwaj <sasikanth.bharadwaj>
Severity: normal    
Priority: P3 CC: jarthana, sasikanth.bharadwaj, shankhba, stephan.herrmann
Version: 4.3.2   
Target Milestone: 4.13   
Hardware: PC   
OS: Mac OS X   
Whiteboard:

Description Theodore Murdock CLA 2014-12-22 17:52:20 EST
This code produces no compile error in Eclipse, but (correctly) fails to compile in javac:

class MinimalBrokenExample {
	public static interface I1<F> {
		public void add(F f);
	}

	public static interface I2<G> {
		public void add(G g);
	}

	public static class Super {
		public void add(Integer i) {}

		public void add(Double s) {}
	}

	public static class MyList extends Super implements I1<Integer>, I2<Double> {}

	public static void main(String[] args) {
		((I1<Integer>) new MyList()).add(0);
	}
}

MyList should fail to compile due to a name clash between I1.add() and I2.add() having the same erasure. Instead this compiles without warnings, but casting MyList to I1<Integer> and calling add(0) results in a ClassCastException, because Integer cannot be cast to Double.

In the case of clashing inherited implementations of generic interfaces, whichever of the clashing interfaces comes last in the "implements" list wins and works at runtime, the others fail with a ClassCastException. 

Version information:
Kepler SR2, build ID: 20140224-0627
JDT version: 3.9.2.20140114-1555
Comment 1 Jay Arthanareeswaran CLA 2014-12-23 02:31:56 EST
Shankha, please follow up. This is similar to bug 408031, but about inherited methods.
Comment 2 shankha banerjee CLA 2015-05-15 02:07:53 EDT
Unit test case:
public void testBug456012() {
	runConformTest(
	new String[] {
		"X.java",
		"interface I1<F> { public void add(F f); }\n" +
		"interface I2<G> { public void add(G g); }\n" +
		"class Super {\n" +
		"    public void add(Integer i) {}\n" +
		"    public void add(Double s) {}\n" +
		"}\n" +
		"class MyList extends Super implements I1<Integer>, I2<Double> {}\n" +
		"public class X {\n" +
		"    public static void main(String[] args) {}\n" +
		"}\n"});
}
Comment 3 Eclipse Genie CLA 2019-09-04 16:44:56 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 4 Stephan Herrmann CLA 2019-09-05 04:18:50 EDT
The example from comment 0 is accepted also by javac starting from version 11.

Hence I conclude that javac had a bug that got fixed meanwhile and accepting is probably correct.