support models of generic types
As a baby step toward support of generics, we should support writing models of generic library types and checking uses of those types against the models. E.g., for a Pair<S, T> type, we should be able to write a model indicating the type is really Pair<@PolyNull S, @PolyNull T> and then allowing app code to write, e.g., Pair<@Nullable String, String>. We would not initially check that the implementation of the Pair class respects the model. Depending on implementation difficulty of figuring out how generic types are instantiated, we may require the models to be more or less explicit.
Couple notes based on some initial tinkering:
- We'll need to handle assignments, e.g., you can't assign a
Pair<@Nullable String, String>toPair<String, String>(with both@NonNull). Probably just want to support invariance. - Without inference, ergonomics will be a bit rough. E.g., if you write
Pair<@Nullable String, String> p = new Pair<>(null, "hello");I don't think javac's inference will tell us that the first type parameter for thenewexpression is@Nullable. Would be a bit unfortunate to have to writePair<@Nullable String, String> p = new Pair<@Nullable String, String>(null, "hello");but supporting inference could be a lot more work.
Overall I think adding basic support (even without inference) will be a moderate amount of work to get right.
FWIW Error Prone has some support for generics and null checking now, implemented by @bennostein. See the inference code and this commit. Perhaps we could do something similar in NullAway? @lazaroclapp