Status Update
Comments
ja...@google.com <ja...@google.com>
pa...@google.com <pa...@google.com>
js...@google.com <js...@google.com> #2
I wonder if you need to specify: @Target(ElementType.PARAMETER)
. Otherwise, that is annotated on parameter type int
(or maybe both, as per
js...@google.com <js...@google.com> #3
Actually, just recalled the previous issue:
I'm afraid a workaround to handle duplicate visit on Java synthetic setter (on setter itself and setter parameter) that I recommend at
// Don't visit values assigned to annotated fields or properties, parameters passed to
// annotated methods, or annotated properties being referenced as fields. We'll visit the
// annotated fields and methods separately.
if (referenced is PsiField && type == ASSIGNMENT_RHS ||
referenced is PsiMethod && type == ASSIGNMENT_RHS ||
referenced is PsiMethod && type == FIELD_REFERENCE ||
referenced is PsiMethod && type == METHOD_CALL_PARAMETER
) {
return
}
al...@google.com <al...@google.com> #4
It's not calling visitAnnotationUsage
at all, so I don't think it could be related to that workaround inside visitAnnotationUsage
. I don't think it's the target, either, because none of the following result in a callback (see aosp/2852626):
public Object unsafeAnnotatedAnnotationUsageOnParam(@AnnotatedJavaAnnotation Object param) {
return param;
}
@AnnotatedJavaAnnotation
public Object unsafeAnnotatedAnnotationUsageOnMethod(Object param) {
return param;
}
@AnnotatedJavaAnnotation
class UnsafeAnnotatedAnnotationUsageOnClass {}
js...@google.com <js...@google.com>
js...@google.com <js...@google.com> #5
Somehow this issue is still opened as one of my tabs; before closing it, just tried to reproduce the issue, and noticed two things:
-
AnnotationHandler
never visits value parameter as a declaration at all -
"usages of annotated annotations" are handled, e.g.,
@IntDef
, like an annotation annotated with@IntDef
and tracking call arguments to value parameter; but@AnnotatedJavaAnnotation
needs one step further:AnnotatedJavaAnnotation
's meta annotation,ExperimentalJavaAnnotation
, is annotated with the annotation of interest,RequiresOptIn
.
js...@google.com <js...@google.com> #6
First one---visiting annotation on value parameter as a DECLARATION
usage type---is done/merged.
Second one, though, seems to cause huge overhead if visiting meta annotations over and over again is not guarded...
js...@google.com <js...@google.com> #7
Changes will be available at AGP 8.6.0-alpha03
an...@google.com <an...@google.com> #8
Thank you for your patience while our engineering team worked to resolve this issue. A fix for this issue is now available in:
- Android Studio Koala Feature Drop | 2024.1.2 Canary 3
- Android Gradle Plugin 8.6.0-alpha03
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
Thank you for taking the time to submit feedback — we really appreciate it!
js...@google.com <js...@google.com> #10
I used the exactly same example. Please note that
visiting annotation on value parameter as a
DECLARATION
usage type
because the annotation in question is annotated in a declaration (value parameter).
And that type is off by default:
So you may need to do something like:
override fun isApplicableAnnotationUsage(type: AnnotationUsageType): Boolean {
return when (type) {
AnnotationUsageType.DEFINITION -> true
else -> super.isApplicableAnnotationUsage(type)
}
}
js...@google.com <js...@google.com> #11
As shown at aosp/3108427, I can confirm
js...@google.com <js...@google.com> #12
(The detector also needs to examine meta-level annotations.)
Actually, this is the only reason we didn't see warning. Even though parameter is visited as DECLARATION
usage, it's immediately bailed out at isExperimentalityAccepted
. Rather, when visiting the use-site (which is not DECLARATION
), now the examination of meta-level annotation matters only.
Description
Reproducible using lint
31.3.0-alpha10
.Given a detector with:
We would expect to see a callback to
visitAnnotationUsage
for the usage of@AnnotatedJavaAnnotation
as a parameter annotation; however, this snippet does not receive any callbacks.