Skip to content

Commit dc14ea8

Browse files
committed
Fix regression for nested AnnotationAttributes.annotationType() result
See gh-22738
1 parent 0a03d8e commit dc14ea8

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

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

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 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.
@@ -20,6 +20,7 @@
2020
import java.lang.annotation.Retention;
2121
import java.lang.annotation.RetentionPolicy;
2222
import java.lang.annotation.Target;
23+
import java.util.Arrays;
2324

2425
import org.junit.Test;
2526

@@ -81,7 +82,7 @@ public void indirectlyAnnotatedWithImport() {
8182
}
8283

8384
@Test
84-
public void importRegistrar() throws Exception {
85+
public void importRegistrar() {
8586
ImportedRegistrar.called = false;
8687
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
8788
ctx.register(ImportingRegistrarConfig.class);
@@ -91,7 +92,7 @@ public void importRegistrar() throws Exception {
9192
}
9293

9394
@Test
94-
public void importRegistrarWithImport() throws Exception {
95+
public void importRegistrarWithImport() {
9596
ImportedRegistrar.called = false;
9697
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
9798
ctx.register(ImportingRegistrarConfigWithImport.class);
@@ -120,6 +121,11 @@ public void metadataFromImportsTwoThenOne() {
120121
((StandardAnnotationMetadata) importMetadata).getIntrospectedClass());
121122
}
122123

124+
@Test
125+
public void importAwareWithAnnotationAttributes() {
126+
new AnnotationConfigApplicationContext(ApplicationConfiguration.class);
127+
}
128+
123129

124130
@Configuration
125131
@Import(ImportedConfig.class)
@@ -290,4 +296,41 @@ public ConfigurationPhase getConfigurationPhase() {
290296
}
291297
}
292298

299+
300+
@Configuration
301+
@EnableFeature(policies = {
302+
@EnableFeature.FeaturePolicy(name = "one"),
303+
@EnableFeature.FeaturePolicy(name = "two")
304+
})
305+
public static class ApplicationConfiguration {
306+
}
307+
308+
309+
@Target(ElementType.TYPE)
310+
@Retention(RetentionPolicy.RUNTIME)
311+
@Import(FeatureConfiguration.class)
312+
public @interface EnableFeature {
313+
314+
FeaturePolicy[] policies() default {};
315+
316+
@interface FeaturePolicy {
317+
318+
String name();
319+
}
320+
}
321+
322+
323+
@Configuration
324+
public static class FeatureConfiguration implements ImportAware {
325+
326+
@Override
327+
public void setImportMetadata(AnnotationMetadata annotationMetadata) {
328+
AnnotationAttributes enableFeatureAttributes =
329+
AnnotationAttributes.fromMap(annotationMetadata.getAnnotationAttributes(EnableFeature.class.getName()));
330+
assertEquals(EnableFeature.class, enableFeatureAttributes.annotationType());
331+
Arrays.stream(enableFeatureAttributes.getAnnotationArray("policies")).forEach(featurePolicyAttributes ->
332+
assertEquals(EnableFeature.FeaturePolicy.class, featurePolicyAttributes.annotationType()));
333+
}
334+
}
335+
293336
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public MergedAnnotation<A> filterDefaultValues() {
168168

169169
@Override
170170
public AnnotationAttributes asAnnotationAttributes(Adapt... adaptations) {
171-
return asMap(mergedAnnotation -> new AnnotationAttributes(getType()), adaptations);
171+
return asMap(mergedAnnotation -> new AnnotationAttributes(mergedAnnotation.getType()), adaptations);
172172
}
173173

174174
@Override

0 commit comments

Comments
 (0)