Fix ClassFileMethodMetadata return type names for primitives and arrays on JDK 24+#36577
Open
bebeis wants to merge 1 commit intospring-projects:mainfrom
Open
Fix ClassFileMethodMetadata return type names for primitives and arrays on JDK 24+#36577bebeis wants to merge 1 commit intospring-projects:mainfrom
bebeis wants to merge 1 commit intospring-projects:mainfrom
Conversation
Return correct names for primitive and array types Introduce resolveTypeName helper for ClassDesc handling Add ClassFileMethodMetadataTests (java24Test) Extend AbstractMethodMetadataTests with void return case Signed-off-by: Junseo Bae <ferrater1013@gmail.com>
Member
|
Please hold off further changes here, I'll take care of fixing the failing build and additional cases. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On JDK 24+,
@Beanmethods declared with avoidreturn type are not rejected during configuration parsing, and noBeanDefinitionParsingExceptionis raised.Reproduction
JDK 21 (expected behavior)
JDK 24+ (actual behavior)
No exception is thrown and the context starts normally.
Test Failed
Root cause
On JDK 24+, Spring uses
ClassFileMethodMetadata(backed by the JDK 24 ClassFile API) to read method metadata. ThegetReturnTypeName()method was implemented as:ClassDesc.packageName()is only defined for class and interface types. Using it unconditionally when building return type names causes malformed results for primitive and array types.void".void""void"int".int""int"String"java.lang.String""java.lang.String"String[]".String[]""java.lang.String[]"The most visible symptom is that
BeanMethod.validate()inspring-contextchecks:Because
getReturnTypeName()returns".void"instead of"void"on JDK 24+, this check silently passes — allowingvoid @Beanmethods without any error.Fix
Replaced the inline string concatenation with a
resolveTypeName()helper that handles each case correctly:This ensures:
void,int, etc.).MyClassThis change aligns ClassFile-based metadata with existing ASM and reflection-based implementations.
Tests
ClassFileMethodMetadataTests(java24Test)AbstractMethodMetadataTestsNotes
Similar issues exist in other ClassFile-based implementations (e.g. ClassFileAnnotationDelegate and Source#toString()), where primitive, array, and default package types may also be rendered incorrectly. These are not addressed in this PR.