Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: REM cost reform

...

Unlike the basic for statement, assignments to the loop variable fail to affect the loop's iteration order or the iterated collection or array. . Consequently, an assignment to the loop variable is equivalent to modifying a variable local to the loop body whose initial value is the object referenced by the loop iterator. This modification is not necessarily erroneous but can obscure the loop functionality or indicate a misunderstanding of the underlying implementation of the enhanced for statement.

...

Assignments to the loop variable of an enhanced for loop (for-each idiom) fail to affect the overall iteration order or the iterated collection or array.   This can  lead lead to programmer confusion, and can leave data in a fragile or inconsistent state.

Rule

Severity

Likelihood

Detectable

Remediation CostRepairable

Priority

Level

DCL02-J

Low

Unlikely

Yes

LowNo

P3P2

L3

Automated Detection

ToolVersionCheckerDescription
Klocwork

Include Page
Klocwork_V
Klocwork_V

JD.UNMOD
Parasoft Jtest
Include Page
Parasoft_V
Parasoft_V
CERT.DCL02.ITMODDo not modify collection while iterating over it

...