Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8290110 | 20 | Jan Lahoda | P3 | Resolved | Fixed | b06 |
JDK-8291409 | 19.0.2 | Jan Lahoda | P3 | Resolved | Fixed | b01 |
JDK-8291252 | 19.0.1 | Jan Lahoda | P3 | Resolved | Fixed | b04 |
Consider code like:
---
public class SwitchGuard {
public static void main(String... args) {
test(null);
}
private static void test(Object o) {
switch (o) {
case null, String s when s.isEmpty() -> System.err.println("OK.");
default -> {}
}
}
}
---
when ran, this should print "OK.", but it fails with a NPE:
---
$ java --enable-preview SwitchGuard
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.isEmpty()" because "<local3>" is null
at SwitchGuard.test(SwitchGuard.java:7)
at SwitchGuard.main(SwitchGuard.java:3)
---
---
public class SwitchGuard {
public static void main(String... args) {
test(null);
}
private static void test(Object o) {
switch (o) {
case null, String s when s.isEmpty() -> System.err.println("OK.");
default -> {}
}
}
}
---
when ran, this should print "OK.", but it fails with a NPE:
---
$ java --enable-preview SwitchGuard
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.isEmpty()" because "<local3>" is null
at SwitchGuard.test(SwitchGuard.java:7)
at SwitchGuard.main(SwitchGuard.java:3)
---
- backported by
-
JDK-8290110 A NullPointerException thrown from guard expression
-
- Resolved
-
-
JDK-8291252 A NullPointerException thrown from guard expression
-
- Resolved
-
-
JDK-8291409 A NullPointerException thrown from guard expression
-
- Resolved
-