JDK-8154587 : Resolution fails for default method named 'clone'
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 8u60,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-04-19
  • Updated: 2018-02-16
  • Resolved: 2017-12-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11
11 b01Fixed
Related Reports
Relates :  
Relates :  
Description
If I compile* the following with javac and run, I get a NoSuchMethodError.  Expect it to run without error.

public class DefaultClone {
  interface I1 {
    default Object clone() { return this; }
  }

  interface I2 extends I1 { }
  
  static class C implements I2 {
    public Object clone() { return this; }
  }

  static void test(I2 i) { i.clone(); }

  public static void main(String[] args) {
    test(new C());
  }
}

*Separately, the I1 declaration shouldn't compile at all -- see linked issue.  So producing a future-proof test will require some non-Java bytecode generation.

(Originally reported here: https://twitter.com/lrytz/status/722512917485195270 )
Comments
If I1 shouldn't compile can give you the failing example such that it will and should compile - thanks.
19-04-2016

The offending bytecode: invokeinterface #2, 1 // InterfaceMethod DefaultClone$I2.clone:()Ljava/lang/Object; Per JVMS 5.4.3.4: - 'DefaultClone$I2' is an interface, ok - 'DefaultClone$I2' doesn't declare a method named 'clone', keep going - 'Object' doesn't declare a public, non-static method named 'clone', keep going - Exactly one non-abstract method in the superinterfaces of 'DefaultClone$I2' matches, succeed
19-04-2016