typetools / typetools/checker-framework
Annotation indicating field types
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
I'm trying to express in the nullness checker that fields are non-null in elements of a collection.
I found @EnsuresNonNull and @RequiresNonNull but they can only be applied on functions, not types.
To give an example, I'm looking for something like this hypothetical @NonNullField :
class Person { @MonotonicNonNull Integer age; }
List<@NonNullField("age") person> personsWithAge;
// Now personsWithAge.add behaves as if annotated with @RequiresNonNull("#1.age")
// and personsWithAge.get behaves as if annotated with @EnsuresNonNull("#1.age")
EDIT: Fix annotations.
Is there any way to express this constraint in the Checker Framework today?
If it does not currently exist, it would be a great addition as it would be very useful. It could superseed many use of @EnsuresNonNull, @RequiresNonNull, @AssertNonNullIfNonNull (by putting this annotation on the parameter/return type instead of using expression strings), as well as opening new possibilities for collections (such as in the previous example) and generics.
Of course it would only work for MonotonicNonNull and final fields to keep it sound.
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 reviewing the nullness checker's existing @EnsuresNonNull and @RequiresNonNull annotations and how they are applied to functions. Define whether a type-level @NonNullField annotation can express the proposed collection and generic semantics while remaining sound for MonotonicNonNull and final fields; done should include a clear supported design and validation of the example behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100