typetools / typetools/checker-framework
Permit return type of @MonotonicNonNull
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
It should be permitted to write @MonotonicNonNull on a return type.
A method call to such a method behaves analogously to a field of type @MonotonicNonNull. After the client tests the expression against null, the checker can assume that subsequent uses of the expression are non-null (until the receiver might be re-assigned, for a field or zero-arity method; rules for non-nullary methods would be different and might require purity).
To type-check implementations of methods with @MonotonicNonNull return type, the rules on assignment of @MonotonicNonNull to @MonotonicNonNull need to be relaxed.
Currently such an assignment is forbidden, because the two might be in different states.
However, it is acceptable when a method has a single return statement. Consider the following code, which currently does not type-check but should:
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
public class MonotonicNonNullReturn {
@MonotonicNonNull Object field;
@MonotonicNonNull Object getter() {
return field;
}
}
A less restrictive rule would be that if the lhs has only one assignment (statically), then the assignment is permitted (even though lhs and rhs are both @MonotonicNonNull). When a routine has only one return statement, this is satisfied.
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 locating the nullness checker rules for @MonotonicNonNull return types and assignments, then use the MonotonicNonNullReturn example in the issue as the initial reproduction. Done means the example type-checks and the checker permits the stated single-return assignment behavior while preserving the nullness rules for other cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100