Source: https://mail.openjdk.org/pipermail/compiler-dev/2024-May/026716.html
Copied from the mailing list:
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;
}
}
Copied from the mailing list:
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;
}
}