You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
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
@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.
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.
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.
Activity
[-]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[/+]msridhar commentedon Dec 12, 2024
@N1k145 I tried out your test case. The first thing I see is that the edited
Varargsclass does not compile: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
@Nullablearray in the varargs position, you must annotate the varargs parameter with a type use@Nullableannotation, like JSpecify's@Nullable. If you writefoo(@Nullable String... args)andNullableis a declaration annotation (likejavax.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@Nullableannotation whenever you want to be able to pass a@Nullablevarargs 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 commentedon 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 commentedon Dec 13, 2024
No, any annotation named
@Nullablethat is a type use annotation should work. So, the Checker Framework@Nullableshould 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 commentedon 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 commentedon Dec 13, 2024
Ok! Note that temporarily you can use the JSpecify
@Nullablein this one place while retaining extant annotations elsewhere, if that will unblock you.