Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another varargs @Nullable issue #1090

Closed
msridhar opened this issue Dec 12, 2024 · 5 comments
Closed

Another varargs @Nullable issue #1090

msridhar opened this issue Dec 12, 2024 · 5 comments

Comments

@msridhar
Copy link
Collaborator

msridhar commented Dec 12, 2024

          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

@msridhar msridhar 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 Dec 12, 2024
@msridhar
Copy link
Collaborator Author

@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?

@N1k145
Copy link

N1k145 commented Dec 13, 2024

@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?

@msridhar
Copy link
Collaborator Author

msridhar commented Dec 13, 2024

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.

@N1k145
Copy link

N1k145 commented Dec 13, 2024

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.

@msridhar
Copy link
Collaborator Author

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

@msridhar msridhar closed this as not planned Won't fix, can't repro, duplicate, stale Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants