Details about the known misuse from the MUBench dataset.
Description:
Checks the return value of Map.put() to check whether the key was set before. If the Map allows null values, this usage breaks.
Fix Description:
Use Map.containsKey() to check whether a key is set.
Violation Types:
missing/condition/value_or_state
In File:
MapNull.java
In Method:
misuse(Map)
Code with Misuse:
class MapNull {
public void misuse(Map<String, Object> m) {
if (m.put("foo", new Object()) != null) {
// "foo" was set before
} else {
// "foo" was not set before (or set to null!)
}
}
}