V6016. Suspicious access to element by a constant index inside a loop.
The analyzer detected a possible error that has to do with trying to access the elements of an array or list using the same constant index at each iteration of a 'for' loop.
Consider the following example:
void transform(List<Integer> parameters, ...)
{
for (int i = 0; i < parameters.size(); i++)
{
int element = parameters.get(0);
...
}
...
}
In this code, the programmer wanted the value of the i-th element of the 'parameters' array to be assigned to variable 'element' at each loop iteration, but because of a typo only the first element is accessed all the time. Another explanation is that the programmer probably used the element at index zero for debugging and then forgot to change the index value.
Fixed code:
void transform(List<Integer> parameters, ...)
{
for (int i = 0; i < parameters.size(); i++)
{
int element = parameters.get(i);
...
}
...
}
You can look at examples of errors detected by the V6016 diagnostic. |