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.
- csr of
-
JDK-8321224 ct.sym for JDK 22 contains references to internal modules
- Resolved