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
{{ message }}
Repository navigation
JSpecify: support inference for calls to generic methodsΒ #1075
This will be a significant challenge in general, but maybe we can handle the common cases and do something useful without having a full technique. See here for one test case:
@NullMarked
public class Foo {
public static class Key<T extends @Nullable Object> {}
private static final Key<@Nullable Foo> KEY = new Key();
public static <T extends @Nullable Object> void setValue(Key<T> key, T value) {
}
public static void main() {
setValue(KEY, null);
}
}
FYI, this (or something very similar) came up when Dropwizard upgraded to a new version of Caffeine. Fortunately, in their case, they appear to be better off just removing their usage of @Nullable.
I hope that #1131 will cover many common cases here, but it's a subtle change and we're still working on it. @agrieve once that PR is landed I may ask if you can test on Chromium with a snapshot build.
I'm glad to hear that explicit generics have worked for you. That what I would have hoped / expected, though we definitely aim to eliminate the need for these as much as possible.
error: [NullAway] Cannot pass parameter of type Supplier<Object>, as formal parameter has type Supplier<@org.jspecify.annotations.Nullable R>, which has mismatched type parameter nullability
invoke(() -> null);
^
Hi all, we've made significant improvements in generic method inference on the master branch, which should be released soon in version 0.12.10. I think we're at the point where we should open follow-up issues for specific limitations, to track things more carefully, and we can close this issue on initial support. I've gone through the reports here and opened up one follow-up issue, #1290. Also, #1157 needs to be re-opened. As far as I could see, the other examples reported here work now. We welcome follow-up issues for cases that still don't work! I'll comment back when the release is out.
Activity
agrieve commentedon Jan 8, 2025
Hit this as well.
The specific case I ran into was in this form:
msridhar commentedon Jan 8, 2025
Thanks for the example! We are working on this.
cpovirk commentedon Jan 23, 2025
FYI, this (or something very similar) came up when Dropwizard upgraded to a new version of Caffeine. Fortunately, in their case, they appear to be better off just removing their usage of
@Nullable.agrieve commentedon Mar 4, 2025
Heh, this is coming up more with the new release because now our annotations within generics are being noticed more :P.
Here's a simpler example:
The best work-arounds I've found so far are:
@NullUnmarked:Just sharing in case it's helpful to anyone else.
msridhar commentedon Mar 4, 2025
I hope that #1131 will cover many common cases here, but it's a subtle change and we're still working on it. @agrieve once that PR is landed I may ask if you can test on Chromium with a snapshot build.
I'm glad to hear that explicit generics have worked for you. That what I would have hoped / expected, though we definitely aim to eliminate the need for these as much as possible.
msridhar commentedon Mar 4, 2025
Actually, small correction, we will handle the specific case from #1075 (comment) in a follow-up to #1131
[NullAway] Null unmark Callback#runNullSafe
[NullAway] Null unmark Callback#runNullSafe
sdeleuze commentedon Apr 10, 2025
Not sure if that's the same one, but with:
I am unable to write
new Wrapper<@Nullable String>(null)and currently have to specify@NullUnmarked public Wrapper(T value)to make it work.msridhar commentedon Apr 10, 2025
@sdeleuze I think your latest case may be #1155 rather than this one? I'll try to look at that one soon.
sdeleuze commentedon Apr 10, 2025
Indeed, looks like more related to #1155. Thanks!
[NullAway] Null unmark Callback#runNullSafe
1 remaining item
Workaround NullAway bug on generic types
mhalbritter commentedon Aug 1, 2025
is this the same case or is this a separate issue?
jonatan-ivanov commentedon Aug 1, 2025
@mhalbritter I'm afraid it is, you can try this as a workaround:
Improved inference for generic method calls (#1244)
msridhar commentedon Sep 16, 2025
Hi all, we've made significant improvements in generic method inference on the master branch, which should be released soon in version 0.12.10. I think we're at the point where we should open follow-up issues for specific limitations, to track things more carefully, and we can close this issue on initial support. I've gone through the reports here and opened up one follow-up issue, #1290. Also, #1157 needs to be re-opened. As far as I could see, the other examples reported here work now. We welcome follow-up issues for cases that still don't work! I'll comment back when the release is out.
msridhar commentedon Sep 16, 2025
NullAway 0.12.10 is now released with these changes.
Remove @NullUnmarked workaround for NullAway bug on generic types
Remove @NullUnmarked workaround for NullAway bug on generic types