uber / uber/NullAway

Surprising behavior of `@NullUnmarked` on method overriding `Map.get()`

Open
#730 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
4.1k
Forks
370
Avg merge
1d 13h
Merged PRs (30d)
68

Description

Test case:

https://github.com/uber/NullAway/blob/5d9fbe1215db6c90e71e878239218f9144163f66/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyTests.java#L1138-L1151

A user may expect that annotating the TestMap.get() method as @NullUnmarked would lead to its return being treated as @NonNull. But, our rules dictate that for unannotated code, inherited library models should apply. So, the inherited library model for Map.get() is applied, and the return becomes @Nullable. Not sure whether we need to fix something here, or whether this is unusual but sensible behavior. My intuition is that an explicit @NullUnmarked annotation should "win" over an inherited library method, but that will just make the rules even more complicated...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked test in nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyTests.java, lines 1138-1151, and trace how inherited library models are applied to TestMap.get(). Determine the intended precedence between explicit @NullUnmarked and the Map.get() model; done means a documented decision and a regression test for the chosen behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.