Skip to content

Commit a194fa0

Browse files
committed
Merge branch '5.3.x'
# Conflicts: # spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java
2 parents 36cf1ac + 07960d4 commit a194fa0

File tree

2 files changed

+65
-64
lines changed

2 files changed

+65
-64
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,10 @@ private void addConventionMappings() {
271271
int[] mappings = this.conventionMappings;
272272
for (int i = 0; i < mappings.length; i++) {
273273
String name = this.attributes.get(i).getName();
274-
MirrorSet mirrors = getMirrorSets().getAssigned(i);
275274
int mapped = rootAttributes.indexOf(name);
276275
if (!MergedAnnotation.VALUE.equals(name) && mapped != -1) {
277276
mappings[i] = mapped;
277+
MirrorSet mirrors = getMirrorSets().getAssigned(i);
278278
if (mirrors != null) {
279279
for (int j = 0; j < mirrors.size(); j++) {
280280
mappings[mirrors.getAttributeIndex(j)] = mapped;
@@ -509,7 +509,6 @@ Object getMappedAnnotationValue(int attributeIndex, boolean metaAnnotationsOnly)
509509
* @return {@code true} if the value is equivalent to the default value
510510
*/
511511
boolean isEquivalentToDefaultValue(int attributeIndex, Object value, ValueExtractor valueExtractor) {
512-
513512
Method attribute = this.attributes.get(attributeIndex);
514513
return isEquivalentToDefaultValue(attribute, value, valueExtractor);
515514
}

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

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,70 @@ void searchFromNonAnnotatedStaticNestedClassWithAnnotatedEnclosingClassWithEnclo
207207

208208
}
209209

210+
@Nested
211+
class ConventionBasedAnnotationAttributeOverrideTests {
212+
213+
@Test
214+
void getWithInheritedAnnotationsAttributesWithConventionBasedComposedAnnotation() {
215+
MergedAnnotation<?> annotation =
216+
MergedAnnotations.from(ConventionBasedComposedContextConfigurationClass.class,
217+
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
218+
assertThat(annotation.isPresent()).isTrue();
219+
assertThat(annotation.getStringArray("locations")).containsExactly("explicitDeclaration");
220+
assertThat(annotation.getStringArray("value")).containsExactly("explicitDeclaration");
221+
}
222+
223+
@Test
224+
void getWithInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation1() {
225+
// SPR-13554: convention mapping mixed with AliasFor annotations
226+
// xmlConfigFiles can be used because it has an AliasFor annotation
227+
MergedAnnotation<?> annotation =
228+
MergedAnnotations.from(HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass1.class,
229+
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
230+
assertThat(annotation.getStringArray("locations")).containsExactly("explicitDeclaration");
231+
assertThat(annotation.getStringArray("value")).containsExactly("explicitDeclaration");
232+
}
233+
234+
@Test
235+
void withInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation2() {
236+
// SPR-13554: convention mapping mixed with AliasFor annotations
237+
// locations doesn't apply because it has no AliasFor annotation
238+
MergedAnnotation<?> annotation =
239+
MergedAnnotations.from(HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass2.class,
240+
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
241+
assertThat(annotation.getStringArray("locations")).isEmpty();
242+
assertThat(annotation.getStringArray("value")).isEmpty();
243+
}
244+
245+
@Test
246+
void getWithInheritedAnnotationsFromInvalidConventionBasedComposedAnnotation() {
247+
assertThatExceptionOfType(AnnotationConfigurationException.class)
248+
.isThrownBy(() -> MergedAnnotations.from(InvalidConventionBasedComposedContextConfigurationClass.class,
249+
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class));
250+
}
251+
252+
@Test
253+
void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaConvention() {
254+
testGetWithTypeHierarchy(ConventionBasedSinglePackageComponentScanClass.class, "com.example.app.test");
255+
}
256+
257+
@Test
258+
void getWithTypeHierarchyWithLocalAliasesThatConflictWithAttributesInMetaAnnotationByConvention() {
259+
MergedAnnotation<?> annotation =
260+
MergedAnnotations.from(SpringApplicationConfigurationClass.class, SearchStrategy.TYPE_HIERARCHY)
261+
.get(ContextConfiguration.class);
262+
assertThat(annotation.getStringArray("locations")).isEmpty();
263+
assertThat(annotation.getStringArray("value")).isEmpty();
264+
assertThat(annotation.getClassArray("classes")).containsExactly(Number.class);
265+
}
266+
267+
@Test
268+
void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaConvention() throws Exception {
269+
testGetWithTypeHierarchyWebMapping(WebController.class.getMethod("postMappedWithPathAttribute"));
270+
}
271+
272+
}
273+
210274
@Test
211275
void fromPreconditions() {
212276
SearchStrategy strategy = SearchStrategy.DIRECT;
@@ -479,41 +543,7 @@ void getWithInheritedAnnotationsFromNonInheritedAnnotationInterface() {
479543
assertThat(annotation.isPresent()).isTrue();
480544
}
481545

482-
@Test
483-
void getWithInheritedAnnotationsAttributesWithConventionBasedComposedAnnotation() {
484-
MergedAnnotation<?> annotation = MergedAnnotations.from(
485-
ConventionBasedComposedContextConfigurationClass.class,
486-
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
487-
assertThat(annotation.isPresent()).isTrue();
488-
assertThat(annotation.getStringArray("locations")).containsExactly(
489-
"explicitDeclaration");
490-
assertThat(annotation.getStringArray("value")).containsExactly(
491-
"explicitDeclaration");
492-
}
493-
494-
@Test
495-
void getWithInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation1() {
496-
// SPR-13554: convention mapping mixed with AliasFor annotations
497-
// xmlConfigFiles can be used because it has an AliasFor annotation
498-
MergedAnnotation<?> annotation = MergedAnnotations.from(
499-
HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass1.class,
500-
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
501-
assertThat(annotation.getStringArray("locations")).containsExactly(
502-
"explicitDeclaration");
503-
assertThat(annotation.getStringArray("value")).containsExactly(
504-
"explicitDeclaration");
505-
}
506546

507-
@Test
508-
void withInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation2() {
509-
// SPR-13554: convention mapping mixed with AliasFor annotations
510-
// locations doesn't apply because it has no AliasFor annotation
511-
MergedAnnotation<?> annotation = MergedAnnotations.from(
512-
HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass2.class,
513-
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
514-
assertThat(annotation.getStringArray("locations")).isEmpty();
515-
assertThat(annotation.getStringArray("value")).isEmpty();
516-
}
517547

518548
@Test
519549
void withInheritedAnnotationsFromAliasedComposedAnnotation() {
@@ -591,13 +621,6 @@ private void testGetWithInherited(Class<?> element, String... expected) {
591621
assertThat(annotation.getClassArray("classes")).isEmpty();
592622
}
593623

594-
@Test
595-
void getWithInheritedAnnotationsFromInvalidConventionBasedComposedAnnotation() {
596-
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
597-
MergedAnnotations.from(InvalidConventionBasedComposedContextConfigurationClass.class,
598-
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class));
599-
}
600-
601624
@Test
602625
void getWithInheritedAnnotationsFromShadowedAliasComposedAnnotation() {
603626
MergedAnnotation<?> annotation = MergedAnnotations.from(
@@ -760,11 +783,6 @@ void getWithTypeHierarchyFromClassWithBothAttributesOfAnAliasPairDeclared() {
760783
testGetWithTypeHierarchy(ComponentScanWithBasePackagesAndValueAliasClass.class, "com.example.app.test");
761784
}
762785

763-
@Test
764-
void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaConvention() {
765-
testGetWithTypeHierarchy(ConventionBasedSinglePackageComponentScanClass.class, "com.example.app.test");
766-
}
767-
768786
@Test
769787
void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaAliasFor() {
770788
testGetWithTypeHierarchy(AliasForBasedSinglePackageComponentScanClass.class, "com.example.app.test");
@@ -793,22 +811,6 @@ void getWithTypeHierarchyWhenMultipleMetaAnnotationsHaveClashingAttributeNames()
793811
"test.properties");
794812
}
795813

796-
@Test
797-
void getWithTypeHierarchyWithLocalAliasesThatConflictWithAttributesInMetaAnnotationByConvention() {
798-
MergedAnnotation<?> annotation = MergedAnnotations.from(
799-
SpringApplicationConfigurationClass.class, SearchStrategy.TYPE_HIERARCHY).get(
800-
ContextConfiguration.class);
801-
assertThat(annotation.getStringArray("locations")).isEmpty();
802-
assertThat(annotation.getStringArray("value")).isEmpty();
803-
assertThat(annotation.getClassArray("classes")).containsExactly(Number.class);
804-
}
805-
806-
@Test
807-
void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaConvention() throws Exception {
808-
testGetWithTypeHierarchyWebMapping(
809-
WebController.class.getMethod("postMappedWithPathAttribute"));
810-
}
811-
812814
@Test
813815
void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaAliasFor() throws Exception {
814816
testGetWithTypeHierarchyWebMapping(

0 commit comments

Comments
 (0)