Branch: refs/heads/main
Home: https://github.com/pmd/pmd
Commit: 2789d7435b2067038048f3ea948fc054c9b2b70a
https://github.com/pmd/pmd/commit/2789d7435b2067038048f3ea948fc054c9b2b70a
Author: Eljees <[email protected]>
Date: 2026-08-14 (Fri, 14 Aug 2026)
Changed paths:
M docs/pages/release_notes.md
M
pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/GuardLogStatementRule.java
M
pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/GuardLogStatement.xml
Log Message:
-----------
[java] Fix #1287: GuardLogStatement false positive with a guard clause (#6920)
* [java] Fix #1287: GuardLogStatement false positive with a guard clause
hasGuard only looked for the guard among the ancestors of the log call, so the
early-return style guard - a preceding sibling that leaves the block - was not
recognized.
Signed-off-by: Eljees <[email protected]>
* [java] GuardLogStatement: let a guard clause cover nested log statements
Addresses the review on #6920.
- hasEarlyExitGuard now walks up the statement ancestors instead of looking
only at the immediate siblings of the log statement, so an early-exit guard
also covers log statements nested deeper than the guard itself - for example
inside a loop that follows it. This is the case reported in review.
- alwaysExits uses children(...).last() and lets the recursive instanceof
handle the null case, as suggested.
Test cases added:
- log inside a loop after the guard (the reported case)
- log nested several blocks deep after the guard
- a continue guard inside a loop does not guard a log after the loop
- a guard in a sibling if-block does not guard a later log statement
The last two are negative cases: they pin that walking up the ancestors does
not start swallowing real violations. Both already passed before this change,
so they fail if the walk is ever made too permissive.
* review
* [doc] Update release notes (#1287)
---------
Signed-off-by: Eljees <[email protected]>
Co-authored-by: Lukas Gräf <[email protected]>
Co-authored-by: Lukas Gräf <[email protected]>
To unsubscribe from these emails, change your notification settings at
https://github.com/pmd/pmd/settings/notifications
_______________________________________________
Pmd-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pmd-commits