Skip to content

Repeatable annotation container no longer found on custom composed annotation #23856

@Walliee

Description

@Walliee

Looks like migration of AnnotationUtils to use the MergedAnnotations API has introduced a regression to the public static <A extends Annotation> A findAnnotation(Method method, @Nullable Class<A> annotationType) method when finding repeatable annotations that are declared on custom composed annotations.

// Repeatable annotation

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Repeatable(Roles.class)
public @interface Role {
	String value() default "";
}
// Container annotation

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface Roles {
	Role[] value();
}
// Custom composed annotation 

@Retention(RetentionPolicy.RUNTIME)
@Role("role_a")
@Role("role_b")
public @interface MyCustomRole {
}
class MyObject {
	@MyCustomRole
	public void someMethod() {}
}

AnnotationUtils.findAnnotation(someMethod, Roles.class) returns null after upgrading to 5.2.0.RELEASE

I've created a sample here to better demonstrate: https://github.com/Walliee/repeatable-annotations

All 3 tests pass on 5.1.10.RELEASE but only 2 on 5.2.0.RELEASE

Affected versions: 5.2.0.RELEASE

Metadata

Metadata

Labels

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

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions