[java] ImplicitSwitchFallThrough: False negative when fall-through comment is placed after closing brace
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 5.5k
- Forks
- 1.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 54
Description
Affects PMD Version: 7.23.0
Rule: ImplicitSwitchFallThrough — https://docs.pmd-code.org/latest/pmd_rules_java_errorprone.html#implicitswitchfallthrough
Description:
ImplicitSwitchFallThrough does not fire when a case block contains braces without a break, and the trailing comment is placed after the closing brace.
Although the control flow still falls through from case 1 to case 2, PMD fails to detect it in this situation.
Code Sample demonstrating the issue:
public class FallThroughDemo {
// ImplicitSwitchFallThrough is NOT reported, but fall-through still occurs
public static String processB(int opcode, String cst) {
String result = cst;
switch (opcode) {
case 1: {
result = result.toLowerCase(); // Line7:ImplicitSwitchFallThrough should be reported
} // and fall through...
case 2: {
result = result.trim();
break;
}
default: {
result = "";
break;
}
}
return result;
}
}
Actual outcome: PMD should report a violation at line 7, but doesn't. This is a false-negative.
Running PMD through: CLI
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ImplicitSwitchFallThrough rule and reproduce the Java example through the CLI, focusing on the case block with braces and the comment after its closing brace. Add coverage for this example and verify that PMD reports a violation at line 7, confirming the false negative is fixed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 64/100