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

Access to private classes should be permitted inside the permits clause of the enclosing top-level class

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3
    • 24
    • 23, 24
    • tools
    • None

    Description

      Based on:
      https://mail.openjdk.org/pipermail/amber-dev/2024-August/008911.html

      Consider this code:
      ```
      public sealed class Perm permits Perm.C {
          private final static class C extends Perm {}
      }
      ```

      Compiling it leads to:
      ```
      $ ./javac -fullversion
      javac full version "23+37-2369"

      $ ./javac /tmp/Perm.java
      /tmp/Perm.java:1: error: C has private access in Perm
      public sealed class Perm permits Perm.C {
                                           ^
      /tmp/Perm.java:2: error: class is not allowed to extend sealed class: Perm (as it is not listed in its 'permits' clause)
          private final static class C extends Perm {}
                               ^
      2 errors
      ```

      This is not correct based on the current specification. JLS 8.1.6 says:
      Every TypeName must name an accessible class (§6.6), or a compile-time error occurs.

      And JLS 6.6.1 says:
      Otherwise, the member or constructor is declared private. Access is permitted only when one of the following is true:
      ...
      Access occurs in the permits clause of the top level class or interface that encloses the declaration of the member.
      ...

      So, it appears that the "C" class should be accessible inside the permitted clause. Please see JDK-8284011.

      Attachments

        Issue Links

          Activity

            People

              vromero Vicente Arturo Romero Zaldivar
              jlahoda Jan Lahoda
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: