From 8637540678637c306d38f0681b8c057c791c5c94 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 12 Feb 2019 09:07:51 +0100 Subject: [PATCH] Expose empty annotation array as empty AnnotationAttributes array Closes gh-22405 --- .../ConfigurationClassPostProcessorTests.java | 25 ++++++++++++++++++- .../RecursiveAnnotationArrayVisitor.java | 8 ++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java index b8daeec4de..1b197f4ac3 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -184,6 +184,20 @@ public class ConfigurationClassPostProcessorTests { assertSupportForComposedAnnotationWithExclude(beanDefinition); } + @Test + public void postProcessorWorksWithExtendedConfigurationWithAttributeOverrideForExcludesFilterUsingReflection() { + RootBeanDefinition beanDefinition = new RootBeanDefinition( + ExtendedConfigurationWithAttributeOverrideForExcludeFilter.class); + assertSupportForComposedAnnotationWithExclude(beanDefinition); + } + + @Test + public void postProcessorWorksWithExtendedConfigurationWithAttributeOverrideForExcludesFilterUsingAsm() { + RootBeanDefinition beanDefinition = new RootBeanDefinition( + ExtendedConfigurationWithAttributeOverrideForExcludeFilter.class.getName()); + assertSupportForComposedAnnotationWithExclude(beanDefinition); + } + @Test public void postProcessorWorksWithComposedComposedConfigurationWithAttributeOverridesUsingReflection() { RootBeanDefinition beanDefinition = new RootBeanDefinition( @@ -1515,6 +1529,15 @@ public class ConfigurationClassPostProcessorTests { public static class ComposedConfigurationWithAttributeOverrideForExcludeFilter { } + @ComponentScan(basePackages = "org.springframework.context.annotation.componentscan.base", excludeFilters = {}) + public static class BaseConfigurationWithEmptyExcludeFilters { + } + + @ComponentScan(basePackages = "org.springframework.context.annotation.componentscan.simple", + excludeFilters = @ComponentScan.Filter(Component.class)) + public static class ExtendedConfigurationWithAttributeOverrideForExcludeFilter extends BaseConfigurationWithEmptyExcludeFilters { + } + @ComposedConfigurationWithAttributeOverrides @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/RecursiveAnnotationArrayVisitor.java b/spring-core/src/main/java/org/springframework/core/type/classreading/RecursiveAnnotationArrayVisitor.java index a4530bb79b..3e5bcff04a 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/RecursiveAnnotationArrayVisitor.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/RecursiveAnnotationArrayVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,7 +89,11 @@ class RecursiveAnnotationArrayVisitor extends AbstractRecursiveAnnotationVisitor try { Class attributeType = annotationType.getMethod(this.attributeName).getReturnType(); if (attributeType.isArray()) { - this.attributes.put(this.attributeName, Array.newInstance(attributeType.getComponentType(), 0)); + Class elementType = attributeType.getComponentType(); + if (elementType.isAnnotation()) { + elementType = AnnotationAttributes.class; + } + this.attributes.put(this.attributeName, Array.newInstance(elementType, 0)); } } catch (NoSuchMethodException ex) {