Skip to content

JSpecify: false positive when ? super T is on the both sides of call and T is nullable #1500

@unv-unv

Description

@unv-unv
@NullMarked
public class Test {
    static class Foo<T extends @Nullable Object> {
        public static <T extends @Nullable Object> Foo<T> of(Foo<? super T> foo) {
            return new Foo<>();
        }

        public Foo<T> or(Foo<? super T> other) {
            return this;
        }
    }

    // BUG: [NullAway] incompatible types: Foo<Void> cannot be converted to Foo<@Nullable Void>
    static final Foo<@Nullable Void> FOO = Foo.of(new Foo<@Nullable Void>()).or(new Foo<@Nullable Void>());
}

Note that if I remove call for .or() everything compiles OK.

static final Foo<@Nullable Void> FOO = Foo.of(new Foo<@Nullable Void>());

The following one is OK too:

static final Foo<@Nullable Void> FOO_BASE = Foo.of(new Foo<@Nullable Void>());
static final Foo<@Nullable Void> FOO = FOO_BASE.or(new Foo<@Nullable Void>());

So the problem appears only if on the both sides of .or() call is ? super T.

NullAway 0.13.1, Error Prone 2.48.0

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