From ae8f0937cf4c29a6edf0ed2cabdcb2fba306f674 Mon Sep 17 00:00:00 2001 From: Patrick Strawderman Date: Thu, 5 Sep 2024 23:40:32 -0700 Subject: [PATCH] Avoid storing duplicate empty array in MethodParameter field Avoid storing duplicate empty arrays in the parameterAnnotations field of MethodParameter. --- .../main/java/org/springframework/core/MethodParameter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/MethodParameter.java b/spring-core/src/main/java/org/springframework/core/MethodParameter.java index 628558082277..a51418d25bac 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodParameter.java +++ b/spring-core/src/main/java/org/springframework/core/MethodParameter.java @@ -647,7 +647,7 @@ public Annotation[] getParameterAnnotations() { // for inner classes, so access it with the actual parameter index lowered by 1 index = this.parameterIndex - 1; } - paramAnns = (index >= 0 && index < annotationArray.length ? + paramAnns = (index >= 0 && index < annotationArray.length && annotationArray[index].length > 0 ? adaptAnnotationArray(annotationArray[index]) : EMPTY_ANNOTATION_ARRAY); this.parameterAnnotations = paramAnns; } @@ -916,7 +916,7 @@ public Annotation[] getParameterAnnotations() { merged.add(fieldAnn); } } - anns = merged.toArray(new Annotation[0]); + anns = merged.toArray(EMPTY_ANNOTATION_ARRAY); } } catch (NoSuchFieldException | SecurityException ex) {