Skip to content

Commit 4e47006

Browse files
committed
Merge branch '5.1.x'
2 parents 0bdacdd + 106a757 commit 4e47006

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

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

+24-1
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)

Diff for: spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 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.
@@ -363,7 +363,7 @@ private void assertNotException(String attributeName, Object attributeValue) {
363363
private void assertAttributeType(String attributeName, Object attributeValue, Class<?> expectedType) {
364364
if (!expectedType.isInstance(attributeValue)) {
365365
throw new IllegalArgumentException(String.format(
366-
"Attribute '%s' is of type [%s], but [%s] was expected in attributes for annotation [%s]",
366+
"Attribute '%s' is of type %s, but %s was expected in attributes for annotation [%s]",
367367
attributeName, attributeValue.getClass().getSimpleName(), expectedType.getSimpleName(),
368368
this.displayName));
369369
}

Diff for: spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationReadingVisitorUtils.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 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.
@@ -28,6 +28,7 @@
2828
import org.springframework.core.annotation.AnnotationUtils;
2929
import org.springframework.lang.Nullable;
3030
import org.springframework.util.ClassUtils;
31+
import org.springframework.util.CollectionUtils;
3132
import org.springframework.util.LinkedMultiValueMap;
3233
import org.springframework.util.ObjectUtils;
3334

@@ -124,7 +125,7 @@ public static AnnotationAttributes getMergedAnnotationAttributes(
124125

125126
// Get the unmerged list of attributes for the target annotation.
126127
List<AnnotationAttributes> attributesList = attributesMap.get(annotationName);
127-
if (attributesList == null || attributesList.isEmpty()) {
128+
if (CollectionUtils.isEmpty(attributesList)) {
128129
return null;
129130
}
130131

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

+6-2
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) {

Diff for: spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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.
@@ -154,7 +154,7 @@ public void getEnumWithUnknownAttributeName() {
154154
public void getEnumWithTypeMismatch() {
155155
attributes.put("color", "RED");
156156
exception.expect(IllegalArgumentException.class);
157-
exception.expectMessage(containsString("Attribute 'color' is of type [String], but [Enum] was expected"));
157+
exception.expectMessage(containsString("Attribute 'color' is of type String, but Enum was expected"));
158158
attributes.getEnum("color");
159159
}
160160

0 commit comments

Comments
 (0)