Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8164302

No initialization for super interface with default method

XMLWordPrintable

    • b96
    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "9-ea"
      Java(TM) SE Runtime Environment (build 9-ea+131)
      Java HotSpot(TM) 64-Bit Server VM (build 9-ea+131, mixed mode)

      FULL OS VERSION :
      Linux 4.1.15-gentoo-r1 #1 SMP Sat May 21 23:45:31 CEST 2016 x86_64 Intel(R) Core(TM) i7-3632QM CPU @ 2.20GHz GenuineIntel GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      I'm a developer of the JaCoCo code coverage library. While preparing test cases for cyclic Interface initialization I encountered this issue and isolated a simple reproducer.

      According to JVMS 5.5 :
      interface Child is initialized as a result of invokestatic,
      and interface Base supposed to be initialized, because it is superinterface of Child and declares a non-abstract, non-static method.


      THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes

      THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

      REGRESSION. Last worked in version 8u102

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and start the source code below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      $ java -version
      java version "1.8.0_102"
      Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

      $ java BadInterfaceCycle
      base clinit
      child default method
      child clinit
      child static method

      $ java -version
      java version "9-ea"
      Java(TM) SE Runtime Environment (build 9-ea+131)
      Java HotSpot(TM) 64-Bit Server VM (build 9-ea+131, mixed mode)

      $ java BadInterfaceCycle
      child clinit
      child static method

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class BadInterfaceCycle {

        interface Base {
          static final Object BASE_CONST = new Child() {
            {
              System.out.println("base clinit");
            }
          }.childDefaultMethod();

          default void baseDefaultMethod() {
          }
        }

        interface Child extends Base {
          static final Object CHILD_CONST = new Object() {
            {
              System.out.println("child clinit");
            }
          };

          static void childStaticMethod() {
            System.out.println("child static method");
          }

          default Object childDefaultMethod() {
            System.out.println("child default method");
            return null;
          }
        }

        public static void main(String[] args) {
          Child.childStaticMethod();
        }
      }

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

            acorn Karen Kinnear (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: