JDK-8155221 : incorrect method resolution failure with default method overriding `clone`
  • Type: Bug
  • Component: tools
  • Affected Version: 8,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: generic
  • CPU: x86_64
  • Submitted: 2016-04-19
  • Updated: 2016-08-17
  • Resolved: 2016-08-17
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)

FULL OS VERSION :
Darwin lucmac 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
Interface method resolution fails to find a `clone` method in a parent interface. details in https://gist.github.com/lrytz/6f1451031b09381eb872acd031b00b0b

THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes

THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See https://gist.github.com/lrytz/6f1451031b09381eb872acd031b00b0b

EXPECTED VERSUS ACTUAL BEHAVIOR :
No crash
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NoSuchMethodError: A$I2.clone()Ljava/lang/Object;
	at A.f(A.java:12)
	at A.main(A.java:15)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class A {
  public interface I1 {
    default Object clone() { return "hi"; }
  }

  public interface I2 extends I1 { }

  public static class K implements I2 {
    public Object clone() { return "Ka"; }
  }

  public static void f(I2 i) { System.out.println(i.clone()); }

  public static void main(String[] args) {
    f(new K());
  }
}

---------- END SOURCE ----------


Comments
This seems a bug in the routine Types.overridesObjectMethod - it uses MethodSymbol.overrides, which fails if the modifier of the overridden method is not public and we are inside an interface. The check should be rewritten in terms of a more neutral routine, such as Types.overrideEquivalent.
16-08-2016

This issue is reproducible on all the platforms 8uxx - Fail 9 ea b115 - Fail -sh-4.1$ /opt/java/jdk1.8.0_92/bin/javac A.java -sh-4.1$ /opt/java/jdk1.8.0_92/bin/java A Exception in thread "main" java.lang.NoSuchMethodError: A$I2.clone()Ljava/lang/Object; at A.f(A.java:12) at A.main(A.java:15) -sh-4.1$ /opt/java/jdk-9_ea-115/bin/javac A.java -sh-4.1$ /opt/java/jdk-9_ea-115/bin/java A Exception in thread "main" java.lang.NoSuchMethodError: A$I2.clone()Ljava/lang/Object; at A.f(A.java:12) at A.main(A.java:15)
27-04-2016