Details about the known misuse from the MUBench dataset.
Description: | Iterates until i < l.size(), but starts at i = 1. Therefore, skips the last element.
|
Fix Description: |
Change the condition to i <= l.size().
|
Violation Types: |
- superfluous/condition/value_or_state
|
In File: | TooRestrictive.java |
In Method: | misuse(List) |
Code with Misuse: |
class TooRestrictive {
public void misuse(List<String> l) {
for (int i = 1; i < l.size(); i++) {
l.get(i - 1); // the last element of this list is never retrieved
}
}
}
|
Code with Pattern(s): |
public class Iterate {
public void pattern(List<String> l) {
for (int i = 1; i <= l.size(); i++) {
l.get(i - 1);
}
}
}
|