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
mappingFunction is allowed to return null to avoid updating the mapping, and in this case, computeIfAbsent returns null. Also updated overrides in @NullMarked classes.
I added the @PolyNull comment on Map.computeIfAbsent since I think we'd use it here if it were available; didn't add the comment on all the overrides.
That is all true, yet this has been the only(?) case in which I've been holding out hope that we can declare the signature as more restrictive than it really "should" be, just because a @Nullable return type is so inconvenient for 99% of callers. There is some discussion in #102, but beware that the actual title of that issue is about going even further in the opposite direction (as probably no one actually wants), even though the text goes on to mostly discuss the thing proposed here that people reasonably would want :) I'd be interested in your read on it, whether here or there. I do kind of feel like we'll need to go with the "honest" type eventually, though it would be nice to sort out the Kotlin story first, and I haven't found time :(
Ah...bummer. We could change the type of mappingFunction to be Function<? super K, ? extends @Nullable V>, but (inconsistently) leave the return type as V (without a @Nullable). But the current version is safer.
We have an open issue (uber/NullAway#1616) on adding some kind of ad hoc @PolyNull support to NullAway for library models, for orElseGet. We might have to do the same thing here, or just ask users to suppress the warning. I'll have to think about how best to recommend a narrow suppression, though, rather than the entire surrounding method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mappingFunctionis allowed to returnnullto avoid updating the mapping, and in this case,computeIfAbsentreturnsnull. Also updated overrides in@NullMarkedclasses.I added the
@PolyNullcomment onMap.computeIfAbsentsince I think we'd use it here if it were available; didn't add the comment on all the overrides.Discovered in ben-manes/caffeine#2004 (comment)