Skip to content

Commit 8637540

Browse files
committed
Expose empty annotation array as empty AnnotationAttributes array
Closes spring-projectsgh-22405
1 parent 5bb1c3e commit 8637540

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -184,6 +184,20 @@ public void postProcessorWorksWithComposedConfigurationWithAttributeOverrideForE
184184
assertSupportForComposedAnnotationWithExclude(beanDefinition);
185185
}
186186

187+
@Test
188+
public void postProcessorWorksWithExtendedConfigurationWithAttributeOverrideForExcludesFilterUsingReflection() {
189+
RootBeanDefinition beanDefinition = new RootBeanDefinition(
190+
ExtendedConfigurationWithAttributeOverrideForExcludeFilter.class);
191+
assertSupportForComposedAnnotationWithExclude(beanDefinition);
192+
}
193+
194+
@Test
195+
public void postProcessorWorksWithExtendedConfigurationWithAttributeOverrideForExcludesFilterUsingAsm() {
196+
RootBeanDefinition beanDefinition = new RootBeanDefinition(
197+
ExtendedConfigurationWithAttributeOverrideForExcludeFilter.class.getName());
198+
assertSupportForComposedAnnotationWithExclude(beanDefinition);
199+
}
200+
187201
@Test
188202
public void postProcessorWorksWithComposedComposedConfigurationWithAttributeOverridesUsingReflection() {
189203
RootBeanDefinition beanDefinition = new RootBeanDefinition(
@@ -1515,6 +1529,15 @@ public static class ComposedConfigurationWithAttributeOverrideForBasePackage {
15151529
public static class ComposedConfigurationWithAttributeOverrideForExcludeFilter {
15161530
}
15171531

1532+
@ComponentScan(basePackages = "org.springframework.context.annotation.componentscan.base", excludeFilters = {})
1533+
public static class BaseConfigurationWithEmptyExcludeFilters {
1534+
}
1535+
1536+
@ComponentScan(basePackages = "org.springframework.context.annotation.componentscan.simple",
1537+
excludeFilters = @ComponentScan.Filter(Component.class))
1538+
public static class ExtendedConfigurationWithAttributeOverrideForExcludeFilter extends BaseConfigurationWithEmptyExcludeFilters {
1539+
}
1540+
15181541
@ComposedConfigurationWithAttributeOverrides
15191542
@Retention(RetentionPolicy.RUNTIME)
15201543
@Target(ElementType.TYPE)

spring-core/src/main/java/org/springframework/core/type/classreading/RecursiveAnnotationArrayVisitor.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -89,7 +89,11 @@ else if (!this.attributes.containsKey(this.attributeName)) {
8989
try {
9090
Class<?> attributeType = annotationType.getMethod(this.attributeName).getReturnType();
9191
if (attributeType.isArray()) {
92-
this.attributes.put(this.attributeName, Array.newInstance(attributeType.getComponentType(), 0));
92+
Class<?> elementType = attributeType.getComponentType();
93+
if (elementType.isAnnotation()) {
94+
elementType = AnnotationAttributes.class;
95+
}
96+
this.attributes.put(this.attributeName, Array.newInstance(elementType, 0));
9397
}
9498
}
9599
catch (NoSuchMethodException ex) {

0 commit comments

Comments
 (0)