From ad83d5ebd9e75d39b7753f16a16451f52053c200 Mon Sep 17 00:00:00 2001 From: junhyeong9812 Date: Sun, 14 Jun 2026 07:20:55 +0900 Subject: [PATCH 1/2] Render parameter type names in ClassFileMethodMetadata ClassFileMethodMetadata's toString() formatted method parameter types as packageName() + "." + displayName(). Since ClassDesc.packageName() is empty for primitive, array and default-package types, these rendered with a leading dot (for example ".int" and ".String[]") and reference arrays lost their package. The return type already uses ClassFileAnnotationMetadata.resolveTypeName(); apply it to the parameters as well. Signed-off-by: junhyeong9812 --- .../classreading/ClassFileMethodMetadata.java | 2 +- .../ClassFileMethodMetadataToStringTests.java | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 spring-core/src/test/java24/org/springframework/core/type/classreading/ClassFileMethodMetadataToStringTests.java diff --git a/spring-core/src/main/java24/org/springframework/core/type/classreading/ClassFileMethodMetadata.java b/spring-core/src/main/java24/org/springframework/core/type/classreading/ClassFileMethodMetadata.java index be4e0d4761f..d5f9163649c 100644 --- a/spring-core/src/main/java24/org/springframework/core/type/classreading/ClassFileMethodMetadata.java +++ b/spring-core/src/main/java24/org/springframework/core/type/classreading/ClassFileMethodMetadata.java @@ -195,7 +195,7 @@ final class ClassFileMethodMetadata implements MethodMetadata { builder.append(this.methodName); builder.append('('); builder.append(Stream.of(this.descriptor.parameterArray()) - .map(desc -> desc.packageName() + "." + desc.displayName()) + .map(ClassFileAnnotationMetadata::resolveTypeName) .collect(Collectors.joining(","))); builder.append(')'); return builder.toString(); diff --git a/spring-core/src/test/java24/org/springframework/core/type/classreading/ClassFileMethodMetadataToStringTests.java b/spring-core/src/test/java24/org/springframework/core/type/classreading/ClassFileMethodMetadataToStringTests.java new file mode 100644 index 00000000000..5bebcfa928a --- /dev/null +++ b/spring-core/src/test/java24/org/springframework/core/type/classreading/ClassFileMethodMetadataToStringTests.java @@ -0,0 +1,55 @@ +/* + * Copyright 2002-present 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.core.type.classreading; + +import org.junit.jupiter.api.Test; + +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.type.MethodMetadata; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for parameter type rendering by the {@code java.lang.classfile} based + * {@link ClassFileMethodMetadata}'s {@code toString()}. + * + * @author junhyeong9812 + */ +class ClassFileMethodMetadataToStringTests { + + @Test + void toStringRendersParameterTypeNames() throws Exception { + ClassFileMetadataReaderFactory factory = new ClassFileMetadataReaderFactory(new DefaultResourceLoader()); + MetadataReader reader = factory.getMetadataReader(WithMethod.class.getName()); + MethodMetadata method = reader.getAnnotationMetadata().getDeclaredMethods().stream() + .filter(candidate -> candidate.getMethodName().equals("sample")) + .findFirst() + .orElseThrow(); + // primitive and array parameter types must keep their canonical names, + // not be prefixed with "." (".int", ".String[]") + assertThat(method.toString()).endsWith(".sample(int,java.lang.String[])"); + } + + + @SuppressWarnings("unused") + static class WithMethod { + + public void sample(int number, String[] values) { + } + } + +} From 6316c06a9772a88001e73f04b595eb10ee42f4cb Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Thu, 3 Sep 2026 17:36:26 +0200 Subject: [PATCH 2/2] Polishing contribution See gh-36919 --- .../type/AbstractMethodMetadataTests.java | 15 +++++ .../ClassFileMethodMetadataToStringTests.java | 55 ------------------- 2 files changed, 15 insertions(+), 55 deletions(-) delete mode 100644 spring-core/src/test/java24/org/springframework/core/type/classreading/ClassFileMethodMetadataToStringTests.java diff --git a/spring-core/src/test/java/org/springframework/core/type/AbstractMethodMetadataTests.java b/spring-core/src/test/java/org/springframework/core/type/AbstractMethodMetadataTests.java index 799626afd1b..a7defe230a7 100644 --- a/spring-core/src/test/java/org/springframework/core/type/AbstractMethodMetadataTests.java +++ b/spring-core/src/test/java/org/springframework/core/type/AbstractMethodMetadataTests.java @@ -105,6 +105,12 @@ public abstract class AbstractMethodMetadataTests { assertThat(getTagged(WithMethod.class).getMethodName()).isEqualTo("test"); } + @Test + void toStringMethodShowsPrimitives() { + assertThat(getTagged(WithMethodParameters.class).toString()) + .isEqualTo("public java.lang.String org.springframework.core.type.AbstractMethodMetadataTests$WithMethodParameters.test(java.lang.String[],int)"); + } + @Test void getDeclaringClassReturnsDeclaringClass() { assertThat(getTagged(WithMethod.class).getDeclaringClassName()).isEqualTo(WithMethod.class.getName()); @@ -291,6 +297,15 @@ public abstract class AbstractMethodMetadataTests { } + public static class WithMethodParameters { + + @Tag + public String test(String[] names, int age) { + return ""; + } + + } + public static class WithVoidMethod { @Tag diff --git a/spring-core/src/test/java24/org/springframework/core/type/classreading/ClassFileMethodMetadataToStringTests.java b/spring-core/src/test/java24/org/springframework/core/type/classreading/ClassFileMethodMetadataToStringTests.java deleted file mode 100644 index 5bebcfa928a..00000000000 --- a/spring-core/src/test/java24/org/springframework/core/type/classreading/ClassFileMethodMetadataToStringTests.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2002-present 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.core.type.classreading; - -import org.junit.jupiter.api.Test; - -import org.springframework.core.io.DefaultResourceLoader; -import org.springframework.core.type.MethodMetadata; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for parameter type rendering by the {@code java.lang.classfile} based - * {@link ClassFileMethodMetadata}'s {@code toString()}. - * - * @author junhyeong9812 - */ -class ClassFileMethodMetadataToStringTests { - - @Test - void toStringRendersParameterTypeNames() throws Exception { - ClassFileMetadataReaderFactory factory = new ClassFileMetadataReaderFactory(new DefaultResourceLoader()); - MetadataReader reader = factory.getMetadataReader(WithMethod.class.getName()); - MethodMetadata method = reader.getAnnotationMetadata().getDeclaredMethods().stream() - .filter(candidate -> candidate.getMethodName().equals("sample")) - .findFirst() - .orElseThrow(); - // primitive and array parameter types must keep their canonical names, - // not be prefixed with "." (".int", ".String[]") - assertThat(method.toString()).endsWith(".sample(int,java.lang.String[])"); - } - - - @SuppressWarnings("unused") - static class WithMethod { - - public void sample(int number, String[] values) { - } - } - -}