HandlerMethodParameter defensively handles interface annotation arrays

Issue: SPR-17629
This commit is contained in:
Juergen Hoeller 2019-01-08 00:32:09 +01:00
parent dc2535516c
commit 1faeeaea14
1 changed files with 18 additions and 15 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -481,23 +481,26 @@ public class HandlerMethod {
if (anns == null) { if (anns == null) {
anns = super.getParameterAnnotations(); anns = super.getParameterAnnotations();
for (Annotation[][] ifcAnns : getInterfaceParameterAnnotations()) { for (Annotation[][] ifcAnns : getInterfaceParameterAnnotations()) {
Annotation[] paramAnns = ifcAnns[getParameterIndex()]; int index = getParameterIndex();
if (paramAnns.length > 0) { if (index < ifcAnns.length) {
List<Annotation> merged = new ArrayList<>(anns.length + paramAnns.length); Annotation[] paramAnns = ifcAnns[index];
merged.addAll(Arrays.asList(anns)); if (paramAnns.length > 0) {
for (Annotation paramAnn : paramAnns) { List<Annotation> merged = new ArrayList<>(anns.length + paramAnns.length);
boolean existingType = false; merged.addAll(Arrays.asList(anns));
for (Annotation ann : anns) { for (Annotation paramAnn : paramAnns) {
if (ann.annotationType() == paramAnn.annotationType()) { boolean existingType = false;
existingType = true; for (Annotation ann : anns) {
break; if (ann.annotationType() == paramAnn.annotationType()) {
existingType = true;
break;
}
}
if (!existingType) {
merged.add(adaptAnnotation(paramAnn));
} }
} }
if (!existingType) { anns = merged.toArray(new Annotation[0]);
merged.add(adaptAnnotation(paramAnn));
}
} }
anns = merged.toArray(new Annotation[0]);
} }
} }
this.combinedAnnotations = anns; this.combinedAnnotations = anns;