You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] ForLoopCanBeForeach: inconsistent detection between i += 1 and i = i + 1 update forms #6692
The ForLoopCanBeForeach rule correctly flags standard for loops that can be coverted into enhanced for-each loops when the update expression uses i++ or i += 1. However, it fails to detect the violation (resulting in a False Negative) when the update expression is written as a direct assignment i = i + 1, even though the logic is semantically identical.
Code Sample demonstrating the issue:
importjava.util.List;
publicclassSample {
publicstaticvoidmain(String[] args) {
List<Integer> list = List.of(1, 2, 3, 4, 5, 6);
// Case 1: Flagged correctly by ForLoopCanBeForeachfor (inti = 0; i < list.size(); i += 1) {
System.out.println(list.get(i));
}
// Case 2: NOT flagged (False Negative)for (inti = 0; i < list.size(); i = i + 1) {
System.out.println(list.get(i));
}
}
}
Expected outcome: PMD should report a violation at line 13, but doesn't. This is a false-negative.
Activity
qwerty7878 commentedon May 27, 2026
I'm working on a fix for this.
[doc] Update release notes (pmd#6692)
[java] Fix #6692: ForLoopCanBeForeach detect i = i + 1 update form (#…