From 1faeeaea14f8961a49d280da528fa4623fe7cfee Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 8 Jan 2019 00:32:09 +0100 Subject: [PATCH] HandlerMethodParameter defensively handles interface annotation arrays Issue: SPR-17629 --- .../web/method/HandlerMethod.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java b/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java index bd5ec1917e..3a001fb07f 100644 --- a/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java +++ b/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java @@ -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"); * you may not use this file except in compliance with the License. @@ -481,23 +481,26 @@ public class HandlerMethod { if (anns == null) { anns = super.getParameterAnnotations(); for (Annotation[][] ifcAnns : getInterfaceParameterAnnotations()) { - Annotation[] paramAnns = ifcAnns[getParameterIndex()]; - if (paramAnns.length > 0) { - List merged = new ArrayList<>(anns.length + paramAnns.length); - merged.addAll(Arrays.asList(anns)); - for (Annotation paramAnn : paramAnns) { - boolean existingType = false; - for (Annotation ann : anns) { - if (ann.annotationType() == paramAnn.annotationType()) { - existingType = true; - break; + int index = getParameterIndex(); + if (index < ifcAnns.length) { + Annotation[] paramAnns = ifcAnns[index]; + if (paramAnns.length > 0) { + List merged = new ArrayList<>(anns.length + paramAnns.length); + merged.addAll(Arrays.asList(anns)); + for (Annotation paramAnn : paramAnns) { + boolean existingType = false; + for (Annotation ann : anns) { + if (ann.annotationType() == paramAnn.annotationType()) { + existingType = true; + break; + } + } + if (!existingType) { + merged.add(adaptAnnotation(paramAnn)); } } - if (!existingType) { - merged.add(adaptAnnotation(paramAnn)); - } + anns = merged.toArray(new Annotation[0]); } - anns = merged.toArray(new Annotation[0]); } } this.combinedAnnotations = anns;