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

Inheritance behavior is broken with package visibility over multiple packages

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Centos 7.6, OpenJDK 11.0.2.

      A DESCRIPTION OF THE PROBLEM :
      The entire problem and sample is written up at https://stackoverflow.com/questions/58052667/intheritance-at-package-visibility-in-java

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Please see: https://stackoverflow.com/questions/58052667/intheritance-at-package-visibility-in-java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The inheritance does not follow into packages E and F:

      ((A)a).m();
      A
      ((A)b).m();
      A
      ((A)c).m();
      A
      ((A)d).m();
      D
      ((A)e).m();
      D
      ((A)f).m();
      D
      ((D)d).m();
      D
      ((D)e).m();
      D
      ((D)f).m();
      D
      ACTUAL -
      Note that E and F values around the middle:

      ((A)a).m();
      A
      ((A)b).m();
      A
      ((A)c).m();
      A
      ((A)d).m();
      D
      ((A)e).m();
      E
      ((A)f).m();
      F
      ((D)d).m();
      D
      ((D)e).m();
      D
      ((D)f).m();
      D

      ---------- BEGIN SOURCE ----------
      package a;

      public class A {
          void m() { System.out.println("A"); }
      }

      // ------

      package b;

      import a.A;

      public class B extends A {
          void m() { System.out.println("B"); }
      }

      // ------

      package c;

      import b.B;

      public class C extends B {
          void m() { System.out.println("C"); }
      }

      // ------

      package a;

      import c.C;

      public class D extends C {
          void m() { System.out.println("D"); }
      }

      // ------

      package b;

      import a.D;

      public class E extends D {
          void m() { System.out.println("E"); }
      }

      // ------

      package c;

      import b.E;

      public class F extends E {
          void m() { System.out.println("F"); }
      }

      // --------

      package a;

      import b.B;
      import b.E;
      import c.C;
      import c.F;

      public class Main {

          public static void main(String[] args) {
              A a = new A();
              B b = new B();
              C c = new C();
              D d = new D();
              E e = new E();
              F f = new F();

              System.out.println("((A)a).m();"); ((A)a).m();
              System.out.println("((A)b).m();"); ((A)b).m();
              System.out.println("((A)c).m();"); ((A)c).m();
              System.out.println("((A)d).m();"); ((A)d).m();
              System.out.println("((A)e).m();"); ((A)e).m();
              System.out.println("((A)f).m();"); ((A)f).m();

              System.out.println("((D)d).m();"); ((D)d).m();
              System.out.println("((D)e).m();"); ((D)e).m();
              System.out.println("((D)f).m();"); ((D)f).m();
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: