Files
Mikhail Pyltsinandintellij-monorepo-bot 5b7611c45e [java-inspection] IDEA-310567 'Constant values' false positive for switch expression
- skip 'constant values' for switch expressions if they contain always failed methods

GitOrigin-RevId: 1207911bd11f94f37293254fa609e47b42aa96e1
2024-11-21 14:58:08 +00:00

28 lines
580 B
Java

import org.jetbrains.annotations.Nullable;
class SkipSwitchExpressionWithThrow {
static boolean test(int x) {
return switch (x) {
case 404 -> false;
case 401 -> throw new RuntimeException();
case 403 -> throw new IllegalArgumentException();
default -> throw new IllegalStateException();
};
}
public enum Foo {
A, B
}
public static <R> R exception() {
throw new RuntimeException();
}
@Nullable
public static Object test2(Foo foo) {
return switch (foo) {
case A -> null;
case B -> exception();
};
}
}