typetools / typetools/checker-framework
@Nullable result inferred for @NonNull returning method
Open
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
abstract class Test {
abstract <T> @NonNull T get(Class<T> type);
Collection<Map.Entry<String, String>> getEndpointMap(Stream<Test> tests) {
return tests
.map(val -> Map.entry(val.get(String.class), val.get(String.class)))
.toList();
}
}
compilation fails with
C:\Projects\pvyscomponents\java\libs\kernel\repository\api\src\main\java\com\provys\repository\Test.java:22:30
java: [return] incompatible types in return.
type of expression: @Initialized @NonNull Entry<@Initialized @NonNull String, @Initialized @Nullable String>
method return type: @Initialized @NonNull Entry<@Initialized @NonNull String, @Initialized @NonNull String>
It is a bit strange that if type arguments for Map.entry are specified in offending line, code compiles without warnings
.map(val -> Map.<String, String>entry(val.get(String.class), val.get(String.class)))
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the Java reproducer and comparing inference for Map.entry with and without explicit type arguments. Trace the Checker Framework handling of @NonNull and @Nullable type arguments, then add a regression test showing that the inferred result matches the declared non-null return type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100