Dependent type annotations are not viewpoint-adapted at an anonymous class creation
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start by reading DependentTypesHelper.atInvocation and trace how TreeUtils.elementFromUse(tree) and viewpointAdaptedCopier handle anonymous class constructors. Compare the invocation and super constructor types, including return types, type variables, and the extra enclosing-instance parameter for outer.new Inner(...) {}. Done means javac -processor nullness accepts the anonymous example while preserving the behavior of plain.
Written by the indexing model from the issue text.
Description
Dependent type annotations on a constructor's parameters are not viewpoint-adapted when the constructor is invoked by creating an anonymous class.
import java.util.Map;
import org.checkerframework.checker.nullness.qual.KeyFor;
public class DependentAnon {
static class C {
C(Map<String, Object> m, @KeyFor("#1") String k) {}
}
void plain(Map<String, Object> map, @KeyFor("#1") String key) {
new C(map, key);
}
void anonymous(Map<String, Object> map, @KeyFor("#1") String key) {
new C(map, key) {};
}
}
javac -processor nullness DependentAnon.java accepts plain but issues a false positive for anonymous:
DependentAnon.java:14: error: [argument] incompatible argument for parameter k of C constructor.
new C(map, key) {};
^
found : @KeyFor("map") String
required: @KeyFor("#1") String
The cause is in DependentTypesHelper.atInvocation, which uses TreeUtils.elementFromUse(tree) as the declared executable. For an anonymous class, that is the anonymous constructor, which has no dependent type annotations, so the method returns early. AnnotatedTypeFactory.constructorFromUse copies the super constructor's parameter types, including @KeyFor("#1"), onto the anonymous constructor, but they are never viewpoint-adapted.
Using TreeUtils.getSuperConstructor(tree) there is not enough by itself. atInvocation copies annotations from the declared type to the invocation type position by position (viewpointAdaptedCopier), and the super constructor's type differs from the anonymous constructor's type in its return type, possibly its type variables, and, for outer.new Inner(...) {}, its number of parameters (the anonymous constructor has an extra first parameter for the enclosing instance).
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 61
Getting set up
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.
More from typetools/checker-framework
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
typetools/checker-framework#8043 ·
Maintainers usually reply within 2 days
-
Enforce `@TargetLocations`Possibly taken @w3lld1 claimed this 52 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
typetools/checker-framework#8042 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
typetools/checker-framework#7096 · 1 comment ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
typetools/checker-framework#8392 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 47/100
typetools/checker-framework#8376 ·
Maintainers usually reply within 2 days
All issues in typetools/checker-framework
Similar issues
-
pdfium-drift
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Stirling-Tools/JPDFium#188 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
openremote/openremote#3487 · 1 comment ·
-
Type/Bug U2
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
wso2/product-is#28675 ·
Maintainers usually reply within 1 day
-
a:bug
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
erupts/erupt#460 · 1 comment ·
Maintainers usually reply within 1 day