typetools / typetools/checker-framework
Field assignment with @NotOnlyInitialized fails
Open
@smillst is already working on this.
Since Feb 22, 2021.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
When creating a circular reference between two classes using the @NotOnlyInitialized annotation on the fields the assignment fails if done inline in the field declaration, but succeeds if done in the constructor. Included code samples below to demonstrate the behavior.
This fails:
class BClass {
@NotOnlyInitialized private final AClass other = new AClass(this);
}
But this succeeds:
class BClass {
@NotOnlyInitialized private final AClass other;
BClass() {
other = new AClass(this);
}
}
It's not clear to me that this is intended output and it's not described in the documentation, I had to discover through trial and error.
Failing example:
Succeeding example:
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.
Assessment
This issue has not been assessed yet.