Skip to content

Regression in merged annotation resolution #22654

Closed
@christophstrobl

Description

@christophstrobl

Related to #22586.

Merged annotations used as meta annotations seems to no longer resolve attributes.
Simplified test below passes for 5.1.5.RELEASE and fails for current 5.2.0.BUILD-SNAPSHOT.

Result for 5.1.5: BaseAnnotation(name=custom-name, val1=true)
Result for 5.2.0: BaseAnnotation(name=base-name, val1=false)

@Test
public void resolveWithCustomAnnotationUsingComposedAnnotationAsMeta() {

  java.lang.reflect.Field field = ReflectionUtils.findField(Sample.class,
      it -> it.getName().equals("value"));

  BaseAnnotation annotation = AnnotatedElementUtils.findMergedAnnotation(field, BaseAnnotation.class);

  assertThat(annotation.name()).isEqualTo("custom-name");
  assertThat(annotation.val1()).isTrue();
}

static class Sample {

  @CustomAnnotationWithComposedMeta 
  String value;
}

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.ANNOTATION_TYPE, ElementType.FIELD })
@interface BaseAnnotation {

  String name() default "base-name";
  boolean val1() default false;
}

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.ANNOTATION_TYPE, ElementType.FIELD })
@BaseAnnotation
@interface ComposedAnnotation {

  @AliasFor(annotation = BaseAnnotation.class, attribute = "name")
  String customName() default "composed-name";

  @AliasFor(annotation = BaseAnnotation.class, attribute = "val1")
  boolean foo() default false;
}


@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD })
@ComposedAnnotation(customName = "custom-name", foo = true)
@interface CustomAnnotationWithComposedMeta {}

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions