typetools / typetools/checker-framework
Permit assignment to @MonotonicNonNull in constructor
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
Every possibly-nullable assignment to a @MonotonicNonNull field is prohibited.
However, such an assignment should be permitted as the first assignment to the field in a constructor, if the field was not initialized to a possibly non-null value at its declaration. (That is, it was not initialized, or it was initialized to null.)
Here is an example:
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
class Issue2215Parent {
@MonotonicNonNull Object a;
@MonotonicNonNull Object b = null;
@MonotonicNonNull Object c = possiblyNull();
@MonotonicNonNull Object d = new Object();
static @Nullable Object possiblyNull() {
return null;
}
}
public class Issue2215 extends Issue2215Parent {
@MonotonicNonNull Object f;
@MonotonicNonNull Object g = null;
@MonotonicNonNull Object h = Issue2215Parent.possiblyNull();
@MonotonicNonNull Object i = new Object();
Issue2215(@Nullable Object o) {
this.a = o;
this.b = o;
// :: error: (assignment.type.incompatible)
this.c = o;
// :: error: (assignment.type.incompatible)
this.d = o;
// :: error: (assignment.type.incompatible)
this.a = o;
// :: error: (assignment.type.incompatible)
this.b = o;
// :: error: (assignment.type.incompatible)
this.c = o;
// :: error: (assignment.type.incompatible)
this.d = o;
this.f = o;
this.g = o;
// :: error: (assignment.type.incompatible)
this.h = o;
// :: error: (assignment.type.incompatible)
this.i = o;
// :: error: (assignment.type.incompatible)
this.f = o;
// :: error: (assignment.type.incompatible)
this.g = o;
// :: error: (assignment.type.incompatible)
this.h = o;
// :: error: (assignment.type.incompatible)
this.i = o;
}
}
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
Use the Java reproducer in the issue as the starting point and inspect the nullness-checker handling of @MonotonicNonNull field assignments during constructors. Verify that the first possibly-null assignment is accepted only for fields uninitialized or initialized to null, while later assignments and fields initialized to possibly or definitely non-null values still produce the shown diagnostics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100