The following code increments the field counter in an assertion statement. This should be detected by SpotBugs as "side effects in assertion" but it is missed.
class AssertionWithSideEffect {
private int counter = 0;
public int showBug() {
assert ++counter > 0; // side effect in assertion
return counter;
}
}
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 AssertionWithSideEffect.java && \
java -jar $SPOTBUGS_JAR \
-low \
-effort:max \
AssertionWithSideEffect.class
The following code increments the field
counterin an assertion statement. This should be detected by SpotBugs as "side effects in assertion" but it is missed.SpotBugs version:
4.9.2Java:
Temurin openjdk 21.0.7Ran from CLI as the following two commands: