Given the following code:
public class Reproducer {
void statement() {
}
void test() {
switch (2) {
case 0:
switch (3) {
case 1 -> statement();
case 3 -> {
statement();
statement();
}
}
case 2:
statement();
break;
}
}
}
Rewrite adds 3 break statements:
public class Reproducer {
void statement() {
}
void test() {
switch (2) {
case 0:
switch (3) {
case 1 -> statement();
case 3 -> {
statement();
statement();
break; (1)
}
break; (2)
}
break; (3)
case 2:
statement();
break;
}
}
}
I labeled the added breaks in brackets
- Break 1: unnecessary as it is in a switch expression and not statement (in normal switch expressions it will not add this)
- Break 2: Does not compile "Statement must be prepended with case label"
- Break 3: I guess this one is correct. I believe FallThrough like this should never have been a thing in java, but i dont like that a cleanup task drastically changes logic (as a User i wonder now if cleanup it also changed logic somewere else?)
In this example rewrite does nothing (which is correct) just wanted to point out that the Problem seems to be using switch expressions in switch statements.
void doesWork() {
switch (2) {
case 0 -> statement();
case 1 -> {
statement();
statement();
}
}
}
Given the following code:
Rewrite adds 3 break statements:
I labeled the added breaks in brackets
In this example rewrite does nothing (which is correct) just wanted to point out that the Problem seems to be using switch expressions in switch statements.