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

ct.sym for JDK 22 contains references to internal modules

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 22
    • tools
    • None
    • source
    • minimal
    • Hide
      There are two main possible sources of incompatibilities:
      a) javac permitted subtypes of sealed classes outside of the sealed hierarchy when using `--release N` for JDK >N. Such classes would not be loadable at runtime, and hence are highlighly unlikely they would be used in practice.
      b) for cast-related constructs, javac permitted casts and `instanceof` checks that are illegal due to the sealed hierarchies, see Problem for an example. While it is possible in principle programs may exist accidentally leveraging this mistake, they would only compile with `--release N` on JDK >N, which makes them unlikely. There appears to be 70 sealed public classes in JDK 21, so the code would need to use this for one of these classes. Moreover around 20 of them are related to the Foreign Functions and Memory preview feature. Given the combination of a limited number of classes, and a limited possibility of such compilations, it seems rare real-world programs would run into issues.
      Show
      There are two main possible sources of incompatibilities: a) javac permitted subtypes of sealed classes outside of the sealed hierarchy when using `--release N` for JDK >N. Such classes would not be loadable at runtime, and hence are highlighly unlikely they would be used in practice. b) for cast-related constructs, javac permitted casts and `instanceof` checks that are illegal due to the sealed hierarchies, see Problem for an example. While it is possible in principle programs may exist accidentally leveraging this mistake, they would only compile with `--release N` on JDK >N, which makes them unlikely. There appears to be 70 sealed public classes in JDK 21, so the code would need to use this for one of these classes. Moreover around 20 of them are related to the Foreign Functions and Memory preview feature. Given the combination of a limited number of classes, and a limited possibility of such compilations, it seems rare real-world programs would run into issues.
    • Other
    • JDK

      Summary

      Historical data for past JDK releases are missing the list of permitted subclasses for sealed classes and interfaces, making those sealed types non-sealed.

      Problem

      The historical data for past JDK releases are not recording the permitted subclasses for types correctly. As a consequence, certain casts and subtyping hierarchies are allowed when using --release N for JDK >N, despite being illegal. Consider for example JDK 21 and JDK 22 javac:

      public class C {
          public static void main(String... args) {
              Runnable r = null;
              System.err.println((Thread.Builder) r);
              System.err.println(r instanceof Thread.Builder);
          }
      
          private abstract class CCC implements Thread.Builder {}
      }
      $ JDK21/javac /tmp/C.java
      /tmp/C.java:4: error: incompatible types: Runnable cannot be converted to Builder
              System.err.println((Thread.Builder) r);
                                                  ^
      /tmp/C.java:5: error: incompatible types: Runnable cannot be converted to Builder
              System.err.println(r instanceof Thread.Builder);
                                 ^
      /tmp/C.java:8: error: class is not allowed to extend sealed class: Builder (as it is not listed in its 'permits' clause)
          private abstract class CCC implements Thread.Builder {}
                           ^
      3 errors
      $ JDK22/javac --release 21 /tmp/C.java 
      $ --no error--

      Solution

      The historical data will be fixed to include permitted subclasses.

      Specification

      No specification change. The historical record will be fixed for JDK release 17-21.

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

              Created:
              Updated:
              Resolved: