-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DLS_DEAD_LOCAL_STORE false-positive in switch #2736
Comments
This might be solved if this JEP 456: "Unnamed Variables & Patterns" is implemented: https://openjdk.org/jeps/456 |
@gtoison yes, that's true, once Java 22 is available, the current behavior will be correct. But until then it isn't. 😄 |
... and once everybody has switched to Java 22 😄 |
I tried SpotBugs |
Hum, I thought this was fixed by #2828 ... The change in #2828 looks for a CHECKCAST followed by an ASTORE at the beginning of a switch case |
As for the code that doesn't work - as I said, none of my cases (around 10 or so) have been fixed... but the original one I've given here seems to work which is strange. 😄 Here are a couple more: return switch (value) {
case Map<?, ?> map -> map.size();
case Set<?> set -> set.size();
case List<?> list -> list.size();
case Collection<?> collection ->
throw new UnsupportedOperationException("Error " + value.getClass());
case null, default -> 0;
}; Gives the warning on private static String getValueType(Object value) {
return switch (value) {
case List<?> list -> "list";
case Map<?, ?> map -> "map";
case Number number -> "number";
case null, default -> "other";
};
} Gives the warning on all |
Thanks for the samples, I have added them in #2937 and they are flagged indeed |
Updating on 4.8.5.0 is removing this DLS for such switches. |
You might run into false positives with 4.8.5 because I had not realized that the bytecode instruction for a switch is either |
This leads to a
DLS_DEAD_LOCAL_STORE
error for them
variable. That's a false-positive because Java doesn't allow the variable name to be omitted.The text was updated successfully, but these errors were encountered: