Repository navigation
[java] Fix #7116: Add ControlFlowInTest rule - #7246
Conversation
|
Compared to main: (comment created at 2026-11-09 12:32:35+00:00 for 3a1cf51) |
|
Thanks for the review! I've removed the explicit Java version, moved the release note to New Rules, added expected line numbers to the tests, and updated the rule to report plain try-finally while allowing try-with-resources without catch clauses. Tests and local verification pass. |
|
Thanks for the approval! I've merged the latest main and resolved the release notes conflict. Local tests and verification pass. Should I leave the merge to a maintainer, or is any further action needed from me? |
|
Hi, just checking — should I merge this PR myself once it’s ready, or will a maintainer handle the merge? Thanks! |
As long as the conflicts are only in the release notes, we'll handle the merge. If the conflicts are also in the code, I'd appreciate it if the submitter could take care of that. |
# Conflicts: # docs/pages/release_notes.md
Describe the PR
Adds the Java best-practices rule
ControlFlowInTestto detect control flowthat can obscure which assertions are executed in test methods.
The rule reports:
As discussed in the issue, the only configuration property is
allowLoops.It defaults to
true. Setting it tofalsealso reports for, enhanced for,while, and do-while loops.
Lambda bodies within test methods are checked. Methods and initializers of
local or anonymous classes are excluded from the enclosing test's analysis.
Try-with-resources without catch clauses is allowed for resource management.
Plain try-finally statements are reported; prefer @AfterEach for test cleanup
where appropriate. A try statement with multiple catch clauses is reported once.
Includes 19 regression test scenarios, rule documentation, and release notes.
Related issues
Fixes #7116
Validation
ControlFlowInTestTest: 19 tests passed, none skipped..\mvnw.cmd -pl pmd-java -am verify: BUILD SUCCESS.Ready?
./mvnw clean verifypasses (checked automatically by github actions)