This is possibly a bug with DA/DU.
public enum Action { IGNORE, REJECT }
private static void bad() {
String s;
switch (getAction()) {
case IGNORE:
s = "foo";
break;
case REJECT:
throw new RuntimeException("REJECTED");
};
System.out.println(s); // <------- variable s might not have been initialized
}
private static void ok() {
String s = switch (getAction()) {
case IGNORE:
yield "foo";
case REJECT:
throw new RuntimeException("REJECTED");
};
System.out.println(s); // ok !
}
reported and discussed in: https://mail.openjdk.org/pipermail/amber-dev/2024-December/009139.html
public enum Action { IGNORE, REJECT }
private static void bad() {
String s;
switch (getAction()) {
case IGNORE:
s = "foo";
break;
case REJECT:
throw new RuntimeException("REJECTED");
};
System.out.println(s); // <------- variable s might not have been initialized
}
private static void ok() {
String s = switch (getAction()) {
case IGNORE:
yield "foo";
case REJECT:
throw new RuntimeException("REJECTED");
};
System.out.println(s); // ok !
}
reported and discussed in: https://mail.openjdk.org/pipermail/amber-dev/2024-December/009139.html