-
Notifications
You must be signed in to change notification settings - Fork 629
Closed
Description
Dead store due to switch fall through is not detected if a loop (for/while) follows the assignment operation, even though the dead store variable is not used in the loop. If other branching syntax (e.g., if-else) follows the assignment, the rule is detected correctly. It only misses if a loop follows.
Below is a reproducible example.
class DeadStoreDueToSwitchFallThrough {
public String showBug(int value) {
String valueType = null;
switch (value % 2) {
case 0:
valueType = "even"; // this falls through and is over-written by valueType = "odd";
for (int i = 0; i < 5; i++) {
System.out.println("Nice even value: " + i);
}
case 1:
valueType = "odd";
break;
default:
valueType = "invalid number";
}
return valueType;
}
}
Expected Outcome: Error raised on block [5-16].
Spotbugs: 4.9.3
Java: Jdk 17
and Jdk 21
Run Method: CLI
as:
javac DeadStoreDueToSwitchFallThrough.java && \
java -jar $SPOTBUGS_JAR -textui -effort:max *.class
Metadata
Metadata
Assignees
Labels
No labels