Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
msridhar opened this issue Feb 3, 2023 · 0 comments
Open

Comments

@msridhar
Copy link
Collaborator

msridhar commented Feb 3, 2023

Test case:

"TestMap.java",
"package com.uber;",
"import org.jspecify.annotations.NullUnmarked;",
"public class TestMap extends java.util.HashMap<String,Object> {",
" @NullUnmarked",
" @Override",
" public Object get(Object key) {",
" return super.get(key);",
" }",
" public String getString(String key) {",
" // should be no error here",
" return (String) get(key);",
" }",
"}")

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant