Skip to content

Feature Request: Allow Supplier<@NonNull Foo> -> Supplier<@Nullable Foo> #1356

@agrieve

Description

@agrieve

It's not safe in general to convert nullness of generic types, but I believe it is safe in one specific (and common) scenario: When the generic type is used only for return values.

E.g.:

String s1;
@Nullable String s2;
s2 = s1; // This is safe

Supplier<String> sup1;
Supplier<@Nullable String> sup2;
sup2 = sup1; // This is safe also.

Currently, sup2 = sup1 triggers a warning, but I think if NullAway could check that generic types are used only in method return types, then it need not warn in this case. Perhaps this would be expensive to compute, and if so, maybe a new annotation?

interface MyInterface<T extends @Nullable @ReturnTypesOnly Object> {...}

(with library model to set this for Supplier)J

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions