Fix ActionHandler nullness annotation #4974
Open
+31
−30
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.
This started with #4922 (comment) while I was looking for the cause for #4965.
In short, results are inserted into the "result map" of
ScriptActionHandler.execute()
even if the result innull
. This conflicts with the null annotation in the method signature, which is inherited fromActionHandler.execute()
. @florian-h05 claimed that thenull
value mean to be inserted, and after some "investigation" I agree. The map stores the "outputs" from theAction
, and the output should be included even if the value isnull
. This means that the nullness annotations are wrong.This leads to incorrect warnings for nullness, but that's not the main reason I think it's worth fixing.
null
s inMap
s in Java is "problematic" because it's not supported by allMap
implementations. Popular implementations likeConcurrentHashMap
doesn't support it, moreover it can easily be misinterpreted becausemap.get()
returnsnull
for these entries, just like it does for non-existing keys. "Popular functions" likecomputeIfAbsent()
can't handle it either, andMap
s withnull
s are probably generally difficult to use with streams. More details about this can be found here.As a consequence, we rarely see
null
inMap
s in Java these days. It's just too many pitfalls, so it is usually avoided. This is a legitimate case for storingnull
s inMap
s, but the combination of the wrong annotation and the fact that we rarely see it, means that chances are great that a developer will assume thatnull
s won't be encountered when dealing with theseMap
s. I think not correcting the annotation is "a bug waiting to happen".Unfortunately, correcting the annotation leads to changes in quite a few files, but fortunately, not a lot of code actually interacts with these
Map
s.I have built all add-ons against a core with the modified annotations, and two add-ons must also have their annotations updated. I will create a separate PR with these changes.