From 84f366c89807cadaa8698e8ed33f7e6395d5fd1f Mon Sep 17 00:00:00 2001 From: Chengang Guan Date: Mon, 5 Oct 2026 14:33:36 +0800 Subject: [PATCH] Improve primitive array handling in AnnotationAttributes.toString() `valueToString` only formatted `Object[]`; primitive arrays such as `int[]`, `boolean[]`, and `double[]` fell through to `String.valueOf` and were rendered as hash-based strings like `[I@1a2b3c`. Use `java.lang.reflect.Array` to iterate over any array type so that `toString()` also produces readable output for primitive arrays. Signed-off-by: Chengang Guan --- .../core/annotation/AnnotationAttributes.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java index 82941489e6d6..73275f36d0be 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java @@ -21,12 +21,12 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; +import java.util.StringJoiner; import org.jspecify.annotations.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; -import org.springframework.util.StringUtils; /** * {@link LinkedHashMap} subclass representing annotation attribute @@ -396,8 +396,13 @@ private String valueToString(@Nullable Object value) { if (value == this) { return "(this Map)"; } - if (value instanceof Object[] objects) { - return "[" + StringUtils.arrayToDelimitedString(objects, ", ") + "]"; + if (value != null && value.getClass().isArray()) { + int length = Array.getLength(value); + StringJoiner sj = new StringJoiner(", ", "[", "]"); + for (int i = 0; i < length; i++) { + sj.add(valueToString(Array.get(value, i))); + } + return sj.toString(); } return String.valueOf(value); }