Details about the known misuse from the MUBench dataset.
Description: | Misses to check that there is another element before calling Iterator.next().
|
Fix Description: |
Check iterator.hasNext() or ensure size of the collection (check size(), isEmpty() or add() an element).
|
Violation Types: |
- missing/condition/value_or_state
|
In File: | OnlyNext.java |
In Method: | misuse(Collection) |
Code with Misuse: |
class OnlyNext {
public Object misuse(Collection<Object> os) {
Iterator<Object> itr = os.iterator();
return itr.next();
}
}
|
Code with Pattern(s): |
public class HasNext {
void pattern(Collection<Object> os) {
Iterator<Object> itr = os.iterator();
if (itr.hasNext()) {
itr.next();
}
}
}
|