Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in merged annotation resolution #22654

Closed
Tracked by #22560
christophstrobl opened this issue Mar 25, 2019 · 2 comments
Closed
Tracked by #22560

Regression in merged annotation resolution #22654

christophstrobl opened this issue Mar 25, 2019 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@christophstrobl
Copy link
Member

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 {}
@sbrannen sbrannen added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression labels Mar 25, 2019
@sbrannen sbrannen added this to the 5.2 M1 milestone Mar 25, 2019
@sbrannen
Copy link
Member

@philwebb, do you have time to look into this one?

@jhoeller jhoeller removed the type: bug A general bug label Mar 25, 2019
@philwebb philwebb self-assigned this Mar 25, 2019
@philwebb
Copy link
Member

@christophstrobl Thanks for the sample, I know the cause and I'm working on a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants