Affects: v5.3.24, v6.0.2


I have the following code:

public class Main2 {

    @Retention(RetentionPolicy.RUNTIME)
    @Repeatable(Anno1Container.class)
    public @interface Anno1 {
        String value();
    }

    @Retention(RetentionPolicy.RUNTIME)
    public @interface Anno1Container {
        Anno1[] value();
    }

    @Retention(RetentionPolicy.RUNTIME)
    @Repeatable(Anno2Container.class)
    public @interface Anno2 {
        String value();
    }

    @Retention(RetentionPolicy.RUNTIME)
    public @interface Anno2Container {
        Anno2[] value();
        int number() default 2; // other attributes
    }

    public static void main(String[] args) throws NoSuchMethodException {
        Method method = Main2.class.getMethod("a");
        System.out.println(AnnotatedElementUtils.findMergedRepeatableAnnotations(method, Anno1.class));
        // [@example.Main2$Anno1("A1_1"), @example.Main2$Anno1("A1_2")]
        System.out.println(AnnotatedElementUtils.findMergedRepeatableAnnotations(method, Anno2.class));
        // []
    }


    @Anno1("A1_1")
    @Anno1("A1_2")
    @Anno2("A2_1")
    @Anno2("A2_2")
    public void a() {
    }
}

AnnotatedElementUtils.findMergedRepeatableAnnotations cannot get results when other attributes ( Anno2Container.number ) exist for the container annotation ( Anno2Container )

In v5.3.23, AnnotatedElementUtils.findMergedRepeatableAnnotations can successfully obtain the above two annotations

Comment From: sbrannen

This is potentially a regression caused by #20279.

I'll investigate it.

Comment From: sbrannen

There is a bug in the logic for RepeatableContainers.StandardRepeatableContainers.computeRepeatedAnnotationsMethod(...) which has existed since Spring Framework 5.2 (when StandardRepeatableContainers was introduced); however, the changes made in conjunction with #20279 made this bug apparent when using AnnotatedElementUtils.findMergedRepeatableAnnotations.

Thus, this is simultaneously a bug and a regression.

Comment From: sbrannen

Anyone encountering this issue in Spring Framework 5.3.24/6.0.2/6.0.3 can work around the bug by using the findMergedRepeatableAnnotations() variant that accepts the container type.

For example, the following allows the provided sample to properly find the repeatable annotations.

AnnotatedElementUtils.findMergedRepeatableAnnotations(method, Anno2.class, Anno2Container.class)

Comment From: ForteScarlet

Anyone encountering this issue in Spring Framework 5.3.24/6.0.2/6.0.3 can work around the bug by using the findMergedRepeatableAnnotations() variant that accepts the container type.

For example, the following allows the provided sample to properly find the repeatable annotations.

java AnnotatedElementUtils.findMergedRepeatableAnnotations(method, Anno2.class, Anno2Container.class)

Thanks, i will try.

Comment From: sbrannen

The fix for this will be available in Spring Framework 5.3.25 and 6.0.3 (as well as the upcoming snapshots for those releases).

Comment From: ghillert

I think this broke a little "hack" I was employing for Coherence Spring to work around the lack of @NonBinding annotation support in Spring 🙂. Over two years I added a related ticket for that: https://github.com/spring-projects/spring-framework/issues/26302