I have some code like this where I store a map to java threadlocal,
import java.util.*;
class Foo {
private final ThreadLocal<Map<String, String>> barMap = ThreadLocal.withInitial(HashMap::new);
}
when enabling the nullness check from checkerframework I get
Error: [type.argument.type.incompatible] incompatible types in type argument.
found : @Initialized @NonNull Map<@Initialized @NonNull String, @Initialized @NonNull String>
required: [extends @Initialized @Nullable Object super null]
I don't understand how to resolve this.
This is a known bug in the Checker Framework. You should suppress the warning.
The Checker Framework currently uses the Java 7 type inference algorithm. Java 8 made a major change to type inference, which requires a re-implementation in the Checker Framework. (The Checker Framework is essentially a compiler in its own right.) That re-implementation is partly done, but has not yet been completed.