Skip to content

Another varargs @Nullable issue #1090

Closed as not planned
Closed as not planned

Description

@msridhar
          I have the same issue even when using classic "javax.annotation" Nullable. And those I can't place like the JSpecify anotations.

Even when both methods are part of the same class (but there is an interface involved, no idea it this creates the same scenario ans in @lukasgraef example)

Originally posted by @N1k145 in #1088 (comment)

And:

@msridhar https://github.com/N1k145/NullAway/tree/issue1088

Activity

  1. changed the title [-]I have the same issue even when using classic "javax.annotation" Nullable. And those I can't place like the JSpecify anotations.[/-] [+]Another varargs `@Nullable` issue[/+] on Dec 12, 2024
  2. msridhar commented on Dec 12, 2024

    @msridhar
    ContributorAuthor

    @N1k145 I tried out your test case. The first thing I see is that the edited Varargs class does not compile:

    NullAway/test-java-lib/src/main/java/com/uber/lib/Varargs.java:17: error: [NullAway] passing @Nullable parameter 'test' where @NonNull is required
        new Varargs().typeUseNullableElements(val, test);
    

    This is due to changes made in NullAway 0.12.0 to better support JSpecify annotations. By default, if you want to be able to pass a @Nullable array in the varargs position, you must annotate the varargs parameter with a type use @Nullable annotation, like JSpecify's @Nullable. If you write foo(@Nullable String... args) and Nullable is a declaration annotation (like javax.annotation.Nullable), NullAway treats that as applying to individual varargs parameters (the more common case), not the varargs array itself. Previously, NullAway behaved differently than this, and if you'd like to re-enable the old behavior, you can temporarily pass the option -XepOpt:NullAway:LegacyAnnotationLocations. But, this option will go away eventually, so my suggestion is to just use the JSpecify @Nullable annotation whenever you want to be able to pass a @Nullable varargs array. See our wiki page for more details, and here for all the details on how NullAway interprets varargs parameter annotations in different modes.

    Does the above answer your question?

  3. N1k145 commented on Dec 13, 2024

    @N1k145

    @msridhar Thank you for the explanation, we did directly the bump to 0.12.1 so we did not use 0.12.0 directly and did not notice the change there.

    So you are saying for this usecase there is now (or actually in the future) a hard dependency on JSpecify?

  4. msridhar commented on Dec 13, 2024

    @msridhar
    ContributorAuthor

    So you are saying for this usecase there is now (or actually in the future) a hard dependency on JSpecify?

    No, any annotation named @Nullable that is a type use annotation should work. So, the Checker Framework @Nullable should work (or you could define your own). If you have a strong reason not to use JSpecify, though, we'd be interested to know about it.

  5. N1k145 commented on Dec 13, 2024

    @N1k145

    No we have nothing against JSpecify but we have not yet looked into it. I read up on it today and we are probably migration over to it in the next weeks, so this can be closed.

  6. msridhar commented on Dec 13, 2024

    @msridhar
    ContributorAuthor

    Ok! Note that temporarily you can use the JSpecify @Nullable in this one place while retaining extant annotations elsewhere, if that will unblock you.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions