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

Unable to access protected nested class from subclass

XMLWordPrintable

    • x86_64
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_131"
      Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux host 4.11.6-1-ARCH #1 SMP PREEMPT Sat Jun 17 08:19:42 CEST 2017 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Under certain conditions, a protected nested class is not visible to a subclass of the outer class. Below is a console transcript demonstrating the issue. Changing the example to instead have B extend A<Integer> causes the example to compile successfully with javac.

      $ cat A.java
      package pkgA;

      public class A<T> {
        protected static class Nested {}
      }

      $ cat B.java
      package pkgB;

      import pkgA.A;

      public class B extends A<B.NestedB> {
        protected static class NestedB extends A.Nested {}
      }

      $ javac A.java B.java
      B.java:6: error: Nested has protected access in A
        protected static class NestedB extends A.Nested {}
                                                ^
      1 error


      REPRODUCIBILITY :
      This bug can be reproduced always.

        1. A.java
          0.1 kB
        2. A.java
          0.1 kB
        3. B.java
          0.1 kB

            fmatte Fairoz Matte
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: