1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
import java.util.HashMap;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.NonNull;
// Test case for Issue 961
// https://github.com/typetools/checker-framework/issues/961
public class Issue961 {
<T> T method(T param, Map<T, Object> map) {
if (map.containsKey(param)) {
@NonNull Object o = map.get(param);
return param;
}
return param;
}
abstract class MapContains<K, V> {
// this isn't initialized, but just ignore the error.
@SuppressWarnings("method.invocation.invalid")
V def = setDef();
Map<K, V> map = new HashMap<>();
V get(K p) {
if (!map.containsKey(p)) {
return def;
}
return map.get(p);
}
abstract V setDef();
}
class MapContains2 {
String get1(Map<Object, String> map, Object k) {
if (!map.containsKey(k)) {
return "";
}
return map.get(k);
}
<KeyTV> String get2(Map<Object, String> map, KeyTV k) {
if (!map.containsKey(k)) {
return "";
}
return map.get(k);
}
}
}
|