typetools / typetools/checker-framework
Refined types in loops should not be cached
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
Because the qualified types of some expressions are cached, the code below does not issue a warning that it should.
class Loop {
@PolyNull String id(@PolyNull String o) {
return o;
}
void loop(boolean condition) {
@NonNull String notNull = "hello";
String nullable = "";
while (condition) {
notNull = nullable; // error, the type of nullable is not cached.
notNull = id(nullable); // no error, the type of id(nullable) is cached.
nullable = null;
}
}
}
When data flow analyzes the code in the loop for the first time, the type of nullable is @NonNull, so the type of id(nullable) is also @NonNull. This type is cached in the AnnotatedTypeFactory and then used on subsequent data flow passes and also when type checking.
Caching should be turned off when data flow is analyzing code in a loop.
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 tracing how the AnnotatedTypeFactory caches qualified expression types during data-flow analysis, using the Loop example in the issue to reproduce the missing warning. Check the behavior across repeated passes through the loop and during type checking. Done means caching is disabled while analyzing loop data flow and the assignment through id(nullable) reports the expected error.
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
- 35/100