Skip to content

Commit

Permalink
Prevent class annotations being stored in method annotation metadata …
Browse files Browse the repository at this point in the history
…+ fix removing annotations (#6948)
  • Loading branch information
dstepanov authored Feb 23, 2022
1 parent acac3f9 commit 6d4c18d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ final class InjectVisitor extends ClassCodeVisitorSupport {
void accept(ClassNode classNode, MethodNode methodNode) {
AnnotationMetadata annotationMetadata
if (AstAnnotationUtils.isAnnotated(node.name, methodNode) || AstAnnotationUtils.hasAnnotation(methodNode, Override)) {
annotationMetadata = AstAnnotationUtils.newBuilder(source, unit).buildForParent(node.name, node, methodNode)
// Class annotations are referenced by concreteClassAnnotationMetadata
annotationMetadata = AstAnnotationUtils.newBuilder(source, unit).buildForParent(node.name, null, methodNode)
annotationMetadata = new AnnotationMetadataHierarchy(concreteClassAnnotationMetadata, annotationMetadata)
} else {
annotationMetadata = new AnnotationMetadataReference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,8 @@ protected void accept(DeclaredType type, Element element, AopProxyWriter aopProx
AnnotationMetadata annotationMetadata;

if (annotationUtils.isAnnotated(introductionType.getName(), method) || JavaAnnotationMetadataBuilder.hasAnnotation(method, Override.class)) {
annotationMetadata = annotationUtils.newAnnotationBuilder().buildForParent(introductionType.getName(), classElement, method);
// Class annotations are referenced by typeAnnotationMetadata
annotationMetadata = annotationUtils.newAnnotationBuilder().buildForParent(introductionType.getName(), null, method);
annotationMetadata = new AnnotationMetadataHierarchy(typeAnnotationMetadata, annotationMetadata);
} else {
annotationMetadata = new AnnotationMetadataReference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,21 @@ public AnnotationMetadata buildForParents(String declaringType, List<T> parents,
if (existing instanceof DefaultAnnotationMetadata) {
// ugly, but will have to do
annotationMetadata = ((DefaultAnnotationMetadata) existing).clone();
if (parents.isEmpty()) {
// Don't need to do anything with existing
return annotationMetadata;
}
} else if (existing instanceof AnnotationMetadataHierarchy) {
final AnnotationMetadata declaredMetadata = ((AnnotationMetadataHierarchy) existing).getDeclaredMetadata();
if (declaredMetadata instanceof DefaultAnnotationMetadata) {
annotationMetadata = ((DefaultAnnotationMetadata) declaredMetadata).clone();
} else {
annotationMetadata = new MutableAnnotationMetadata();
}
if (parents.isEmpty()) {
// Don't need to do anything with existing
return annotationMetadata;
}
} else {
annotationMetadata = new MutableAnnotationMetadata();
}
Expand Down

0 comments on commit 6d4c18d

Please sign in to comment.