Skip to content

Commit

Permalink
Add guards for annotation type API to avoid incorrectly resolved type…
Browse files Browse the repository at this point in the history
… annotations as for example emitted by Kotlin.
  • Loading branch information
raphw committed Jan 11, 2020
1 parent 423e570 commit 1f63d1a
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3288,6 +3288,9 @@ protected ForWildcardUpperBoundType(AnnotationReader annotationReader, int index

@Override
protected AnnotatedElement resolve(AnnotatedElement annotatedElement) {
if (!GET_ANNOTATED_UPPER_BOUNDS.getDeclaringClass().isInstance(annotatedElement)) { // Avoid problem with Kotlin compiler.
return NoOp.INSTANCE;
}
try {
Object annotatedUpperBounds = GET_ANNOTATED_UPPER_BOUNDS.invoke(annotatedElement, NO_ARGUMENTS);
return Array.getLength(annotatedUpperBounds) == 0 // Wildcards with a lower bound do not define annotations for their implicit upper bound.
Expand Down Expand Up @@ -3332,6 +3335,9 @@ protected ForWildcardLowerBoundType(AnnotationReader annotationReader, int index

@Override
protected AnnotatedElement resolve(AnnotatedElement annotatedElement) {
if (!GET_ANNOTATED_LOWER_BOUNDS.getDeclaringClass().isInstance(annotatedElement)) { // Avoid problem with Kotlin compiler.
return NoOp.INSTANCE;
}
try {
return (AnnotatedElement) Array.get(GET_ANNOTATED_LOWER_BOUNDS.invoke(annotatedElement, NO_ARGUMENTS), index);
} catch (ClassCastException ignored) { // To avoid bug on early releases of Java 8.
Expand Down Expand Up @@ -3373,6 +3379,9 @@ protected ForTypeVariableBoundType(AnnotationReader annotationReader, int index)

@Override
protected AnnotatedElement resolve(AnnotatedElement annotatedElement) {
if (!GET_ANNOTATED_BOUNDS.getDeclaringClass().isInstance(annotatedElement)) { // Avoid problem with Kotlin compiler.
return NoOp.INSTANCE;
}
try {
return (AnnotatedElement) Array.get(GET_ANNOTATED_BOUNDS.invoke(annotatedElement, NO_ARGUMENTS), index);
} catch (ClassCastException ignored) { // To avoid bug on early releases of Java 8.
Expand Down Expand Up @@ -3462,6 +3471,9 @@ protected ForTypeArgument(AnnotationReader annotationReader, int index) {

@Override
protected AnnotatedElement resolve(AnnotatedElement annotatedElement) {
if (!GET_ANNOTATED_ACTUAL_TYPE_ARGUMENTS.getDeclaringClass().isInstance(annotatedElement)) { // Avoid problem with Kotlin compiler.
return NoOp.INSTANCE;
}
try {
return (AnnotatedElement) Array.get(GET_ANNOTATED_ACTUAL_TYPE_ARGUMENTS.invoke(annotatedElement, NO_ARGUMENTS), index);
} catch (ClassCastException ignored) { // To avoid bug on early releases of Java 8.
Expand Down Expand Up @@ -3495,6 +3507,9 @@ protected ForComponentType(AnnotationReader annotationReader) {

@Override
protected AnnotatedElement resolve(AnnotatedElement annotatedElement) {
if (!GET_ANNOTATED_GENERIC_COMPONENT_TYPE.getDeclaringClass().isInstance(annotatedElement)) { // Avoid problem with Kotlin compiler.
return NoOp.INSTANCE;
}
try {
return (AnnotatedElement) GET_ANNOTATED_GENERIC_COMPONENT_TYPE.invoke(annotatedElement, NO_ARGUMENTS);
} catch (ClassCastException ignored) { // To avoid bug on early releases of Java 8.
Expand Down Expand Up @@ -3542,6 +3557,9 @@ protected ForOwnerType(AnnotationReader annotationReader) {

@Override
protected AnnotatedElement resolve(AnnotatedElement annotatedElement) {
if (!GET_ANNOTATED_OWNER_TYPE.getDeclaringClass().isInstance(annotatedElement)) { // Avoid problem with Kotlin compiler.
return NoOp.INSTANCE;
}
try {
AnnotatedElement annotatedOwnerType = (AnnotatedElement) GET_ANNOTATED_OWNER_TYPE.invoke(annotatedElement, NO_ARGUMENTS);
return annotatedOwnerType == null
Expand Down

0 comments on commit 1f63d1a

Please sign in to comment.