Skip to content

SF_DEAD_STORE_DUE_TO_SWITCH_FALLTHROUGH_TO_THROW not raised #3449

@csrma

Description

@csrma

The following code does not raise the SF_DEAD_STORE_DUE_TO_SWITCH_FALLTHROUGH_TO_THROW although the while loop does not use the result variable (making it a dead store) and the switch falls through to throw.

class DeadStoreBug {
    public int showBug(int input) {
        int i = 0;
        int result = 0;
        switch (input) {
            case 1:
                result = 10;
                while (i < input) {
                    System.out.println(i);
                    i++;
                }
            case 2:
                throw new RuntimeException("Invalid input");
            default:
                result = input * 2;
        }
        return result;
    }
}

SpotBugs version: 4.9.2
Java: Temurin openjdk 21.0.7
Ran from CLI as the following two commands:

export SPOTBUGS_JAR=/path/to/spotbugs.jar
javac DeadStoreBug.java && \
java -jar $SPOTBUGS_JAR \
    -low \
    -effort:max \
    DeadStoreBug.class

Expectation: raises SF_DEAD_STORE_DUE_TO_SWITCH_FALLTHROUGH_TO_THROW.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions