Skip to content

Commit 46be176

Browse files
committed
Allow AnnoConfigEx to propagate from getRepeatableAnnotation()
Issue: SPR-13084
1 parent 8f23378 commit 46be176

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,7 @@ static void postProcessAnnotationAttributes(AnnotatedElement element, Annotation
14861486
* it will be cast to an {@code AnnotationConfigurationException} and thrown,
14871487
* allowing it to propagate to the caller.
14881488
* <p>Otherwise, this method does nothing.
1489+
* @param t the throwable to inspect
14891490
* @since 4.2
14901491
*/
14911492
static void rethrowAnnotationConfigurationException(Throwable t) {
@@ -1621,6 +1622,7 @@ private List<A> getValue(AnnotatedElement element, Annotation annotation) {
16211622
return synthesizedAnnotations;
16221623
}
16231624
catch (Exception ex) {
1625+
rethrowAnnotationConfigurationException(ex);
16241626
// Unable to read value from repeating annotation container -> ignore it.
16251627
return Collections.emptyList();
16261628
}

spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,15 @@ public void getRepeatableFromMethod() throws Exception {
504504
assertThat(values, equalTo(Arrays.asList("a", "b", "c", "meta")));
505505
}
506506

507+
@Test
508+
public void getRepeatableWithMissingAttributeAliasDeclaration() throws Exception {
509+
exception.expect(AnnotationConfigurationException.class);
510+
exception.expectMessage(containsString("Attribute [value] in"));
511+
exception.expectMessage(containsString(BrokenContextConfig.class.getName()));
512+
exception.expectMessage(containsString("must be declared as an @AliasFor [locations]"));
513+
getRepeatableAnnotation(BrokenConfigHierarchyTestCase.class, BrokenHierarchy.class, BrokenContextConfig.class);
514+
}
515+
507516
@Test
508517
public void getRepeatableWithAttributeAliases() throws Exception {
509518
Set<ContextConfig> annotations = getRepeatableAnnotation(ConfigHierarchyTestCase.class, Hierarchy.class,
@@ -1261,19 +1270,38 @@ public void handleMappedWithDifferentPathAndValueAttributes() {
12611270
String locations() default "";
12621271
}
12631272

1273+
@Retention(RetentionPolicy.RUNTIME)
1274+
@interface BrokenContextConfig {
1275+
1276+
// Intentionally missing:
1277+
// @AliasFor(attribute = "locations")
1278+
String value() default "";
1279+
1280+
@AliasFor(attribute = "value")
1281+
String locations() default "";
1282+
}
1283+
12641284
/**
12651285
* Mock of {@code org.springframework.test.context.ContextHierarchy}.
12661286
*/
12671287
@Retention(RetentionPolicy.RUNTIME)
12681288
@interface Hierarchy {
1269-
12701289
ContextConfig[] value();
12711290
}
12721291

1292+
@Retention(RetentionPolicy.RUNTIME)
1293+
@interface BrokenHierarchy {
1294+
BrokenContextConfig[] value();
1295+
}
1296+
12731297
@Hierarchy({ @ContextConfig("A"), @ContextConfig(locations = "B") })
12741298
static class ConfigHierarchyTestCase {
12751299
}
12761300

1301+
@BrokenHierarchy(@BrokenContextConfig)
1302+
static class BrokenConfigHierarchyTestCase {
1303+
}
1304+
12771305
@ContextConfig("simple.xml")
12781306
static class SimpleConfigTestCase {
12791307
}

0 commit comments

Comments
 (0)