From 043442a2a1c29dc4e7252377911f02b4ca935580 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Wed, 30 Sep 2026 13:38:56 +0200 Subject: [PATCH] =?UTF-8?q?Test=20single-value=20to=20primitive=20array=20?= =?UTF-8?q?adaptation=20via=20@=E2=81=A0AliasFor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a test to MergedAnnotationsTests that verifies a single primitive attribute in a composed annotation can be aliased via @⁠AliasFor to a primitive array attribute in a meta-annotation. See gh-37349 --- .../annotation/MergedAnnotationsTests.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java index 61fc0ffe367..0a2d5595da8 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java @@ -596,6 +596,19 @@ class MergedAnnotationsTests { assertThat(annotation.getClassArray("classes")).isEmpty(); } + @Test + void getWithSingleValuePrimitiveAttributesOverridingPrimitiveArraysViaAliasFor() { + MergedAnnotation annotation = MergedAnnotations.from(ComposedPrimitiveSingleValuesClass.class) + .get(PrimitiveArrays.class); + assertThat(annotation.isPresent()).isTrue(); + assertThat(annotation.getIntArray("ints")).containsExactly(42); + assertThat(annotation.getLongArray("longs")).containsExactly(42L); + assertThat(annotation.getBooleanArray("booleans")).containsExactly(true); + assertThat(annotation.getCharArray("chars")).containsExactly('c'); + assertThat(annotation.getDoubleArray("doubles")).containsExactly(4.2d); + assertThat(annotation.synthesize().ints()).containsExactly(42); + } + @Test void getWithInheritedAnnotationsFromShadowedAliasComposedAnnotation() { MergedAnnotation annotation = MergedAnnotations.from( @@ -2274,6 +2287,44 @@ class MergedAnnotationsTests { @interface ComposedTransactionalComponent { } + @Retention(RetentionPolicy.RUNTIME) + @interface PrimitiveArrays { + + int[] ints() default {}; + + long[] longs() default {}; + + boolean[] booleans() default {}; + + char[] chars() default {}; + + double[] doubles() default {}; + } + + @PrimitiveArrays + @Retention(RetentionPolicy.RUNTIME) + @interface ComposedPrimitiveSingleValues { + + @AliasFor(annotation = PrimitiveArrays.class, attribute = "ints") + int anInt() default 0; + + @AliasFor(annotation = PrimitiveArrays.class, attribute = "longs") + long aLong() default 0L; + + @AliasFor(annotation = PrimitiveArrays.class, attribute = "booleans") + boolean aBoolean() default false; + + @AliasFor(annotation = PrimitiveArrays.class, attribute = "chars") + char aChar() default 'x'; + + @AliasFor(annotation = PrimitiveArrays.class, attribute = "doubles") + double aDouble() default 0.0d; + } + + @ComposedPrimitiveSingleValues(anInt = 42, aLong = 42L, aBoolean = true, aChar = 'c', aDouble = 4.2d) + static class ComposedPrimitiveSingleValuesClass { + } + static class NonAnnotatedClass { }