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
public class Example {
private final Function<RedisCache.CachedKey, Map<String, String>> retrieveFn;
...
public Example() {
retrieveFn = redisCache::hgetall; // <<<<<<<<<<<<
}
Hi @daniel-b2c2 supporting this case requires support for writing @Nullable on generic type arguments. Out of the box NullAway does not support this. We are working on adding such support via JSpecify mode (docs). If you enable that, you should be able to write:
But, JSpecify mode support is a WIP, so you may run into other bugs. If you have time to give it a try, let us know. As an alternative, you can suppress the warning.
I'll close this out but if you have further questions please let us know.
I see, do I understand correctly, that JSpecify mode is a mode of operation where NullAway will attempt to apply reasoning based on the JSpecify specification, as opposed to using its own 'internal nullaway' 'engine'/'rules'?
So if I enable JSpecify mode I may see errors that were not there before, while using nullaway?
Asking because a recent guava update where they've switched annotations to use jspecify seems to have created a fresh set of coding errors when using nullaway.
Further to this I saw a new version of nullaway, and I'm also finding new 'bugs' here too.
I will probably just surpress the warnings for now until JSpecify becomes stable.
I see, do I understand correctly, that JSpecify mode is a mode of operation where NullAway will attempt to apply reasoning based on the JSpecify specification, as opposed to using its own 'internal nullaway' 'engine'/'rules'?
Basically, JSpecify mode adds support for checking generic types and other features that NullAway didn't support before. Since it's a large, risky change, and still incomplete, it's not enabled by default yet.
So if I enable JSpecify mode I may see errors that were not there before, while using nullaway?
Correct. But, as you've observed, with generics, it may enable you to get rid of errors that required a suppression when running without JSpecify mode. Unfortunately there isn't a clear winner at this point.
Asking because a recent guava update where they've switched annotations to use jspecify seems to have created a fresh set of coding errors when using nullaway.
We need to document this; in fact I opened #1193 on it. My recommendation is to try JSpecify mode to see how it works for you. I expect if there are false positives, they will be due mostly to #1075, and you can either suppress or (for now) add explicit type annotations to work around. You can feel free to report any other false warnings you run into. But overall, if you're a heavy Guava user, JSpecify mode may work better for you. FWIW, NullAway already being used successfully in JSpecify mode by some major projects like Caffeine. You can just expect possibly more churn in errors as you bump NullAway versions (including more true warnings).
I hope that helps. Please let me know if you have more questions.
Activity
msridhar commentedon Apr 4, 2025
Hi @daniel-b2c2 supporting this case requires support for writing
@Nullableon generic type arguments. Out of the box NullAway does not support this. We are working on adding such support via JSpecify mode (docs). If you enable that, you should be able to write:But, JSpecify mode support is a WIP, so you may run into other bugs. If you have time to give it a try, let us know. As an alternative, you can suppress the warning.
I'll close this out but if you have further questions please let us know.
daniel-b2c2 commentedon Apr 15, 2025
@msridhar sorry for the late response.
I see, do I understand correctly, that JSpecify mode is a mode of operation where NullAway will attempt to apply reasoning based on the JSpecify specification, as opposed to using its own 'internal nullaway' 'engine'/'rules'?
So if I enable JSpecify mode I may see errors that were not there before, while using nullaway?
Asking because a recent guava update where they've switched annotations to use jspecify seems to have created a fresh set of coding errors when using nullaway.
Further to this I saw a new version of nullaway, and I'm also finding new 'bugs' here too.
I will probably just surpress the warnings for now until JSpecify becomes stable.
msridhar commentedon Apr 15, 2025
Basically, JSpecify mode adds support for checking generic types and other features that NullAway didn't support before. Since it's a large, risky change, and still incomplete, it's not enabled by default yet.
Correct. But, as you've observed, with generics, it may enable you to get rid of errors that required a suppression when running without JSpecify mode. Unfortunately there isn't a clear winner at this point.
We need to document this; in fact I opened #1193 on it. My recommendation is to try JSpecify mode to see how it works for you. I expect if there are false positives, they will be due mostly to #1075, and you can either suppress or (for now) add explicit type annotations to work around. You can feel free to report any other false warnings you run into. But overall, if you're a heavy Guava user, JSpecify mode may work better for you. FWIW, NullAway already being used successfully in JSpecify mode by some major projects like Caffeine. You can just expect possibly more churn in errors as you bump NullAway versions (including more true warnings).
I hope that helps. Please let me know if you have more questions.