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
$ checker/bin/javac -processor org.checkerframework.checker.nullness.NullnessChecker Merge.java && java Merge
Exception in thread "main" java.lang.NullPointerException
at Merge.main(Merge.java:8)
The fix would be either:
Require remappingFunction to return a V (not @Nullable V). This reduces expressiveness, but my guess is that users rarely use the ability to return null. (For what it's worth, I didn't notice this bug from actually returning null from a merge function. I just happened to notice it when looking at the stub for Map.)
Change the return type of merge to @Nullable V. This preserves expressiveness but may inconvenience the average caller of merge. (This is of course somewhat like Map.get. However, @KeyFor can't help much here. And it would be mildly unfortunate for users to pass a non-null value and a function that never returns null and yet have to handle null.)
I don't believe @PolyNull is a solution here, at least not by itself: If the user has an empty Map<String, @Nullable String>, then map.merge("k", null, someFunction) will return null, even if someFunction never returns null. To use @PolyNull, we'd need to also change the value parameter's type to @NonNull V.
The problem is that the stubs permit the merge function to return
null
but don't declare thatmerge
itself can then return that to the user:checker-framework/checker/jdk/nullness/src/java/util/Map.java
Lines 1206 to 1207 in 02db22b
The fix would be either:
remappingFunction
to return aV
(not@Nullable V
). This reduces expressiveness, but my guess is that users rarely use the ability to returnnull
. (For what it's worth, I didn't notice this bug from actually returningnull
from a merge function. I just happened to notice it when looking at the stub forMap
.)merge
to@Nullable V
. This preserves expressiveness but may inconvenience the average caller ofmerge
. (This is of course somewhat likeMap.get
. However,@KeyFor
can't help much here. And it would be mildly unfortunate for users to pass a non-null value and a function that never returnsnull
and yet have to handlenull
.)I don't believe
@PolyNull
is a solution here, at least not by itself: If the user has an emptyMap<String, @Nullable String>
, thenmap.merge("k", null, someFunction)
will returnnull
, even ifsomeFunction
never returnsnull
. To use@PolyNull
, we'd need to also change thevalue
parameter's type to@NonNull V
.Source file and
-version -verbose -AprintAllQualifiers
output attached.The text was updated successfully, but these errors were encountered: