Branch: refs/heads/main
Home: https://github.com/pmd/pmd
Commit: dd5b3e5be7c7f81c006c017184fbf0da45b64e91
https://github.com/pmd/pmd/commit/dd5b3e5be7c7f81c006c017184fbf0da45b64e91
Author: fudian <[email protected]>
Date: 2026-09-12 (Sat, 12 Sep 2026)
Changed paths:
M docs/pages/release_notes.md
M
pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SimplifyConditionalRule.java
M pmd-java/src/main/resources/category/java/design.xml
M
pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/SimplifyConditional.xml
Log Message:
-----------
[java] Fix #6513: SimplifyConditional detects null check separated from
instanceof by a && chain (#6946)
* [java] Fix #6513: SimplifyConditional detects null check separated from
instanceof by a && chain
The rule only checked the operand directly adjacent to the instanceof for a
null check on the same subject. When additional conditions sit in the same
&& (or || with negated instanceof) chain, the adjacent operand is itself a
compound expression and the redundant null check was missed.
Traverse the whole sibling short-circuit chain, reusing isNullCheck with the
existing StablePathMatcher so null checks on unrelated expressions are still
ignored. Adds && / || chain regression tests plus a negative test.
Signed-off-by: 付典 <[email protected]>
* [java] Fix #6513: detect the redundant null check at any position in the
short-circuit chain
Scan all leaf operands of the surrounding same-operator chain in
evaluation order instead of only the sibling of the instanceof, so the
null check is reported whether it comes before or after the instanceof,
or the instanceof sits in the middle, in both the && and the negated ||
form. Several redundant null checks on the same subject are each
reported; with several instanceofs on the subject in one chain, only
the first one reports, so null checks are not reported once per
instanceof. Describe in the rule that within a chain, the instanceof
must be evaluated before other operands using the subject once the
null check is dropped.
* [java] Fix #6513: dedicated message when the null check alone cannot be
removed
When an operand evaluated between the null check and the instanceof uses
the subject, removing the null check alone could make it throw a
NullPointerException; report those chains with a message suggesting to
move the instanceof first instead. Null checks and instanceofs on the
subject in between cannot throw, and operands after the instanceof stay
guarded by it, so there the null check can simply be removed and the
default message is kept. Both messages are pinned with expected-messages
in the rule tests.
* undo changes to design.xml.
"We don't have bug X anymore" belongs in the changelog, not in the rule
description.
* Replace message.
We don't only check for nullchecks before an instanceof, but also for
nullchecks after an instanceof, so the old message didn't fit anymore.
---------
Signed-off-by: 付典 <[email protected]>
Co-authored-by: Sören Glimm <[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