Skip to content

Commit 1faeeae

Browse files
committed
HandlerMethodParameter defensively handles interface annotation arrays
Issue: SPR-17629
1 parent dc25355 commit 1faeeae

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java

Lines changed: 18 additions & 15 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.
@@ -481,23 +481,26 @@ public Annotation[] getParameterAnnotations() {
481481
if (anns == null) {
482482
anns = super.getParameterAnnotations();
483483
for (Annotation[][] ifcAnns : getInterfaceParameterAnnotations()) {
484-
Annotation[] paramAnns = ifcAnns[getParameterIndex()];
485-
if (paramAnns.length > 0) {
486-
List<Annotation> merged = new ArrayList<>(anns.length + paramAnns.length);
487-
merged.addAll(Arrays.asList(anns));
488-
for (Annotation paramAnn : paramAnns) {
489-
boolean existingType = false;
490-
for (Annotation ann : anns) {
491-
if (ann.annotationType() == paramAnn.annotationType()) {
492-
existingType = true;
493-
break;
484+
int index = getParameterIndex();
485+
if (index < ifcAnns.length) {
486+
Annotation[] paramAnns = ifcAnns[index];
487+
if (paramAnns.length > 0) {
488+
List<Annotation> merged = new ArrayList<>(anns.length + paramAnns.length);
489+
merged.addAll(Arrays.asList(anns));
490+
for (Annotation paramAnn : paramAnns) {
491+
boolean existingType = false;
492+
for (Annotation ann : anns) {
493+
if (ann.annotationType() == paramAnn.annotationType()) {
494+
existingType = true;
495+
break;
496+
}
497+
}
498+
if (!existingType) {
499+
merged.add(adaptAnnotation(paramAnn));
494500
}
495501
}
496-
if (!existingType) {
497-
merged.add(adaptAnnotation(paramAnn));
498-
}
502+
anns = merged.toArray(new Annotation[0]);
499503
}
500-
anns = merged.toArray(new Annotation[0]);
501504
}
502505
}
503506
this.combinedAnnotations = anns;

0 commit comments

Comments
 (0)