static vs. default interface methods and inheritance VM/javac issues

Peter Levart peter.levart at gmail.com
Thu Sep 12 07:59:21 PDT 2013


Hi,

While testing behavior of reflection on default and static interface 
methods, using self-built JDK from latest tip of jdk8/tl, I found:

The following program:

public class DefaultVsStaticInterfaceMethodTest {
     public interface A {
         default void m() {
             System.out.println("A.m() called");
         }
     }

     public interface B {
         static void m() {
             System.out.println("B.m() called");
         }
     }

     public interface C extends A, B {
     }

     public static void main(String[] args) throws Exception {
         C c = new C() {};
         c.m();
     }
}


...compiles, but gives a runtime error:

Exception in thread "main" java.lang.AbstractMethodError: Conflicting 
default methods: DefaultVsStaticInterfaceMethodTest$A.m 
DefaultVsStaticInterfaceMethodTest$B.m
     at 
DefaultVsStaticInterfaceMethodTest$1.m(DefaultVsStaticInterfaceMethodTest.java)
     at 
DefaultVsStaticInterfaceMethodTest.main(DefaultVsStaticInterfaceMethodTest.java:28)


A slightly modified program: "C extends A, B" replaced with "C extends 
B, A":

http://cr.openjdk.java.net/~plevart/jdk8-tl/StaticVsDefaultInterfaceMethods/DefaultVsStaticInterfaceMethodTest.java

...also compiles, but crashes the VM when run:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fd4d5020bf9, pid=9964, tid=140552419804928
#
# JRE version: OpenJDK Runtime Environment (8.0) (build 
1.8.0-internal-peter_2013_09_12_16_29-b00)
# Java VM: OpenJDK 64-Bit Server VM (25.0-b48 mixed mode linux-amd64 
compressed oops)
# Problematic frame:
# j  DefaultVsStaticInterfaceMethodTest.main([Ljava/lang/String;)V+9
#
# Failed to write core dump. Core dumps have been disabled. To enable 
core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/peter/work/git/jdk8-tl/out/production/test/hs_err_pid9964.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#
Aborted (core dumped)


Here's the hs_err_pid file:

http://cr.openjdk.java.net/~plevart/jdk8-tl/StaticVsDefaultInterfaceMethods/hs_err_pid9964.log



Regards, Peter

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/attachments/20130912/72941cc6/attachment.html 


More information about the hotspot-runtime-dev mailing list