Compiling the following code:
sealed class Permits<X, Y> permits X, Y { }
results in a javac crash:
$ javac -XDdev Permits.java
Permits.java:1: error: illegal forward reference
sealed class Permits<X, Y> permits X, Y { }
^
Permits.java:1: error: illegal forward reference
sealed class Permits<X, Y> permits X, Y { }
^
Permits.java:1: error: class Permits in unnamed module cannot extend a sealed class in a different package
sealed class Permits<X, Y> permits X, Y { }
^
3 errors
An exception has occurred in the compiler (17.0.13). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
at jdk.compiler/com.sun.tools.javac.util.List.get(List.java:490)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5248)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5185)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5143)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1320)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:946)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
printing javac parameters to: /***/javac.20250113_141923.args
This comes from the fact that the types referenced in the permits clause are already erroneous, and the duplication check detects a duplication (as the erroneous type is the same), but the types don't have a diagnostic position.
Additionally, the package mismatch error isn't helpful, it's just a follow-up error.
sealed class Permits<X, Y> permits X, Y { }
results in a javac crash:
$ javac -XDdev Permits.java
Permits.java:1: error: illegal forward reference
sealed class Permits<X, Y> permits X, Y { }
^
Permits.java:1: error: illegal forward reference
sealed class Permits<X, Y> permits X, Y { }
^
Permits.java:1: error: class Permits in unnamed module cannot extend a sealed class in a different package
sealed class Permits<X, Y> permits X, Y { }
^
3 errors
An exception has occurred in the compiler (17.0.13). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
at jdk.compiler/com.sun.tools.javac.util.List.get(List.java:490)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5248)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5185)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5143)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1320)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:946)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
printing javac parameters to: /***/javac.20250113_141923.args
This comes from the fact that the types referenced in the permits clause are already erroneous, and the duplication check detects a duplication (as the erroneous type is the same), but the types don't have a diagnostic position.
Additionally, the package mismatch error isn't helpful, it's just a follow-up error.
- links to
-
Commit(master) openjdk/jdk/8193ba3d
-
Review(master) openjdk/jdk/23069