Skip to content

Inference failure calling unmarked method #1790

Description

@jeffrey-easyesi

With NullAway:WarnOnGenericInferenceFailure enabled, this code now gets a warning:

import org.jspecify.annotations.*;

@NullUnmarked
class StringUtils {
    static <T extends CharSequence> T defaultIfEmpty(T str, T defaultStr) {
        return str == null || str.isEmpty() ? defaultStr : str;
    }
}

@NullMarked
class Test {
    static String f(@Nullable String s) {
        return StringUtils.defaultIfEmpty(s, ""); // inference failure: type variable T constrained to be both @NonNull and @Nullable
    }
}

I think this is a false positive: defaultIfEmpty's parameter and return types are unspecified-nullness and shouldn't be constraining T.
(Either .<String>defaultIfEmpty or .<@Nullable String>defaultIfEmpty is allowed with no error.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugjspecifyRelated to support for jspecify standard (see jspecify.dev)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions