From 0df75ff75e15c8691f19d860e7996dd442d63aad Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Tue, 13 May 2025 16:15:00 +0200 Subject: [PATCH] Fix StringIndexOutOfBoundsException with Class-File metadata Closes gh-34882 --- .../type/classreading/ClassFileAnnotationMetadata.java | 3 +-- .../core/type/AbstractAnnotationMetadataTests.java | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/spring-core/src/main/java24/org/springframework/core/type/classreading/ClassFileAnnotationMetadata.java b/spring-core/src/main/java24/org/springframework/core/type/classreading/ClassFileAnnotationMetadata.java index d22ae7af6d..a55fea4169 100644 --- a/spring-core/src/main/java24/org/springframework/core/type/classreading/ClassFileAnnotationMetadata.java +++ b/spring-core/src/main/java24/org/springframework/core/type/classreading/ClassFileAnnotationMetadata.java @@ -37,7 +37,6 @@ import org.springframework.core.annotation.AnnotationFilter; import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.util.ClassUtils; -import org.springframework.util.StringUtils; /** * Parse {@link RuntimeVisibleAnnotationsAttribute} into {@link MergedAnnotations} @@ -100,7 +99,7 @@ abstract class ClassFileAnnotationMetadata { private static String fromTypeDescriptor(String descriptor) { ClassDesc classDesc = ClassDesc.ofDescriptor(descriptor); - return classDesc.isPrimitive() ? "java.lang." + StringUtils.capitalize(classDesc.displayName()) : + return classDesc.isPrimitive() ? classDesc.displayName() : classDesc.packageName() + "." + classDesc.displayName(); } diff --git a/spring-core/src/test/java/org/springframework/core/type/AbstractAnnotationMetadataTests.java b/spring-core/src/test/java/org/springframework/core/type/AbstractAnnotationMetadataTests.java index 7a990fb7f0..35ad18fdf7 100644 --- a/spring-core/src/test/java/org/springframework/core/type/AbstractAnnotationMetadataTests.java +++ b/spring-core/src/test/java/org/springframework/core/type/AbstractAnnotationMetadataTests.java @@ -309,11 +309,11 @@ public abstract class AbstractAnnotationMetadataTests { } @Test - void getAnnotationAttributeVoidType() { + void getAnnotationAttributeIntType() { MultiValueMap attributes = - get(WithVoidType.class).getAllAnnotationAttributes(ComplexAttributes.class.getName()); + get(WithIntType.class).getAllAnnotationAttributes(ComplexAttributes.class.getName()); assertThat(attributes).containsOnlyKeys("names", "count", "type", "subAnnotation"); - assertThat(attributes.get("type")).containsAnyOf(Void.class, void.class); + assertThat(attributes.get("type")).contains(int.class); } @Test @@ -460,9 +460,9 @@ public abstract class AbstractAnnotationMetadataTests { public static class WithComplexAttributeTypes { } - @ComplexAttributes(names = "void", count = TestEnum.ONE, type = void.class, + @ComplexAttributes(names = "void", count = TestEnum.ONE, type = int.class, subAnnotation = @SubAnnotation(name="spring")) - public static class WithVoidType { + public static class WithIntType { }