typetools / typetools/checker-framework
Spurious resource leak type.argument error on uses of `method(SomeClass.class)`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
Given
import org.checkerframework.checker.mustcall.qual.InheritableMustCall;
public abstract class DotClass {
abstract <T> void setup(Class<T> cls);
public void run() {
setup(Resource.class);
}
@InheritableMustCall("free")
public static class Resource {
public void free() {
}
}
}
The resource leak checker reports
DotClass.java:11: error: [type.argument] incompatible type argument for type parameter T extends @MustCall Object of DotClass.setup.
setup(Resource.class);
^
found : @MustCall("free") Resource
required: @MustCall Object
I am not sure why the Checker Framework infers T = @MustCall("free") Resource. Manually specifying the type parameter silences the warning, but is incredibly ugly:
this.<@MustCall({}) Resource>setup(Resource.class);
An awkward cast will also silence the warning:
setup((Class<@MustCall({}) Resource>)Resource.class);
But, it would be nice if the original code were accepted as-is without one of these verbose modifications.
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 compiling the DotClass.java reproducer with the resource leak checker and inspect how the setup(Resource.class) call infers its type argument. The work is done when the original code is accepted without the type.argument warning; add or run a regression test for this example if the repository provides a suitable checker test location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100