Repository navigation
Minor improvements to Map.merge usage of @PolyNull and @NonNull. - #41
Conversation
- The new `TreeMap` method wasn't annotated with `@PolyNull`. - The `Map` method had a stale comment from before [the method began using `@PolyNull`](eisop@20c1642#diff-26e5bec525317a8d6f1c03687b5e99822ffa62956d2904d8c400981a62990b34R1303).
Map.merge @PolyNull usage:Map.merge @PolyNull usage.
wmdietl
left a comment
There was a problem hiding this comment.
Thanks! I have one question about a mismatch with Map.
| */ | ||
| @Override | ||
| public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) { | ||
| public @PolyNull V merge(K key, V value, BiFunction<? super V, ? super V, ? extends @PolyNull V> remappingFunction) { |
There was a problem hiding this comment.
| public @PolyNull V merge(K key, V value, BiFunction<? super V, ? super V, ? extends @PolyNull V> remappingFunction) { | |
| public @PolyNull V merge(K key, @NonNull V value, BiFunction<? super V, ? super V, ? extends @PolyNull V> remappingFunction) { |
Would adding @NonNull to value make sense, to match the signature in Map?
(We would also need to add the import.)
There was a problem hiding this comment.
Thanks, I should really look at this method (and probably some other Java 8 additions in Map) more carefully.
I agree that @NonNull makes sense on value. (And the implementations in Map, HashMap, TreeMap, and presumably others perform a null check, as the doc's first sentence suggests but the "implementation requirements" do not.)
In fact, I think we should go a step further to make the remappingFunction be a BiFunction<? super @NonNull V, ? super @NonNull V, ? extends @PolyNull V>
- The first argument is the old value, which is passed only if it's non-null. (In the null case,
mergeinsertsvalueand returns.) - The second argument is
value, which, as we just discussed, is non-null.
I've updated accordingly, and I'll tentatively do the same in jspecify/jdk#14.
- Use `@NonNull` on the `value` parameter of `TreeMap.merge`. - Use `@NonNull` on the types of the inputs of `remappingFunction`.
Map.merge @PolyNull usage.Map.merge usage of @PolyNull and @NonNull.
wmdietl
left a comment
There was a problem hiding this comment.
Thanks for the further improvements!
eisop-plume-lib/plume-util#93 fixes the downstream failure.
See typetools/jdk#177 (We already have the annotation on `ofNullable`, so we don't need to carry that over.) (eisop#41)
TreeMapmethod wasn't annotated with@PolyNullor@NonNull.Mapmethod had a stale comment from before the method beganusing
@PolyNull.remappingFunctionweren't annotated as@NonNull.