JDK-7188347 : Javac handles method signatures incorrectly when extending generic interfaces
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2012-08-01
  • Updated: 2012-09-06
  • Resolved: 2012-08-01
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Red Hat Enterprise Linux Workstation release 6.1 x86_64 GNU/Linux
Windows XP

A DESCRIPTION OF THE PROBLEM :
The method Object#clone is erroneously marked as inaccessible when defined in a generic interface that���s extended by referencing its raw type and subsequently implemented.

REGRESSION.  Last worked in version 6u31

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Define an interface Foo<T> with a clone method having a signature identical to Object#clone(). Define an interface Bar extending Foo, and a class Baz implementing Bar. Instantiate an instance of Baz and assign it to a variable of type Bar. A compile time error will occur at the site where a caller attempts to clone an instance of Baz. This error will not occur if the instance is explicitly cast to Foo or Baz before cloning. Under the given type hierarchy clone should be visible from Foo, Bar, and Baz.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Classes with the type hierarchy described above should compile correctly, and do so under JDK 6.
ACTUAL -
Javac reports that clone in Foo is defined in an inaccessible class or interface.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Baz.java:10: error: clone() in Foo is defined in an inaccessible class or interface
		return baz.clone().toString();
		          ^
1 error

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public interface Foo<T> extends Cloneable {

	Object clone() throws CloneNotSupportedException;
	
}

public interface Bar extends Foo {
	
}

public class Baz implements Bar {

	@Override
	public Object clone() throws CloneNotSupportedException {
		return super.clone();
	}
	
	public static String test() throws CloneNotSupportedException {
		final Bar baz = new Baz();
		return baz.clone().toString();
	}

}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
This is a regression and the above is verified to compile and run with java 1.6.0_33.