Details about the known misuse from the MUBench dataset.
Description: | To get one (arbitrary) value from a set you can call Set.iterator().next(), but this throws if the set is empty.
|
Fix Description: |
Check that Set.isEmpty() is false.
|
Violation Types: |
- missing/condition/value_or_state
|
In File: | SetFirst.java |
In Method: | misuse(Set) |
Code with Misuse: |
class SetFirst {
public Object misuse(Set<Object> set) {
return set.iterator().next();
}
}
|
Code with Pattern(s): |
public class IsNotEmpty {
void pattern(Set<Object> set) {
if (!set.isEmpty()) {
set.iterator().next();
}
}
}
|