javac NullPointerException record.type

tors tors42 at gmail.com
Tue May 28 10:38:29 UTC 2024


Hi,
I found a javac error, but the Java bug reporting page didn't allow me
to submit the bug. Posting the reproducer here.
Tried on Linux and Windows.

jdk-22.0.1/bin/javac Main.java
...
java.lang.NullPointerException: Cannot invoke
"com.sun.tools.javac.code.Type.isErroneous()" because "record.type" is
null
    at jdk.compiler/com.sun.tools.javac.comp.Flow.makePatternDescription(Flow.java:3471)
...


class Main {

    record A() {};

    public static void main(String[] args) {
        A a1 = new A();
        A a2 = new A();

        ///
        String causesCompilationError = log(
                switch(a1) {
                    case A() -> switch(a2) {
                        case A() -> "A";
                    };
                }
        );
        ///

        String worksNonPattern = log(
                switch(a1) {
                    case A _ -> switch(a2) {
                        case A _ -> "A";
                    };
                }
        );

        String worksNonNested = log(
                switch(a1) {
                    case A() -> "A";
                }
        );
     }

    static <T> T log(T t) {
        System.out.println("LOG: " + t);
        return t;
    }
}


---
BR,
tors


More information about the compiler-dev mailing list