typetools / typetools/checker-framework
Annotation arguments use defaulting rules for return types
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
In BaseTypeVisitor#visitAnnotation, the expected type for an argument to an annotation is defaulted using the rules for TypeUseLocation.RETURN, which is unintuitive (and ought to at least be documented somewhere). I would expect it to use the defaulting rules for TypeUseLocation.PARAMETER. Here's the relevant code in BaseTypeVisitor:
// Mapping from argument simple name to its annotated type.
Map<String, AnnotatedTypeMirror> annoTypes = new HashMap<>();
for (Element encl : ElementFilter.methodsIn(anno.getEnclosedElements())) {
AnnotatedExecutableType exeatm =
(AnnotatedExecutableType) atypeFactory.getAnnotatedType(encl);
AnnotatedTypeMirror retty = exeatm.getReturnType();
annoTypes.put(encl.getSimpleName().toString(), retty);
}
I'm not sure whether this is a problem for other checkers; I encountered it while building a taint-tracking checker for constants (i.e. all constants are tainted, everything else is untainted). Any use of an annotation with an argument led to an annotation.type.incompatible error, because my analysis uses optimistic defaults - so the default for a return type defined in bytecode is bottom (untainted). But, an annotation argument is logically a parameter (which would have been defaulted to top). In my case, this was easy to resolve (all annotation arguments must be literals, so just override visitAnnotation to do nothing), but I'm filing this issue at @mernst's request to discuss whether this defaulting should change or be documented somewhere.
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 in BaseTypeVisitor#visitAnnotation and trace how the return type from each annotation method is defaulted through TypeUseLocation.RETURN. Compare that behavior with TypeUseLocation.PARAMETER and consider the issue's two stated outcomes: changing annotation arguments to parameter defaulting or documenting the existing rule. Confirm the resulting behavior for the taint-tracking checker scenario described.
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
- Mostly clear
- Newbie friendliness
- 35/100