Details about the known misuse from the MUBench dataset.
| Description: | HashMap.get() throws if the key is null. Since you don't know which implementation of Map you get, you should always guard against this.
|
| Fix Description: |
Check that the key is not null before calling Map.get().
|
| Violation Types: |
- missing/condition/null_check
|
| In File: | MapKeyNull.java |
| In Method: | misuse(HashMap, String) |
| Code with Misuse: |
class MapKeyNull {
Object misuse(HashMap<String, Object> m, String key) {
return m.get(key);
}
}
|
| Code with Pattern(s): |
public class CheckKeyNotNull {
public Object pattern(HashMap<String, Object> m, String key) {
if (key != null) {
return m.get(key);
} else {
return null;
}
}
}
|