Repository navigation
Fix single-value adaptation for primitive array types in TypeMappedAnnotation - #37349
Merged
sbrannen merged 1 commit intoSep 30, 2026
Conversation
…notation Prior to this commit, `adaptForAttribute(Method, Object)` created the wrapping array from `value.getClass()` when a single non-array value was provided for an array attribute. This worked for object array types but failed for primitive array types: wrapping a boxed value produced a boxed array, which then failed the compatibility check and threw an `IllegalStateException`. This commit derives the component type from the declared attribute type when it is assignable from the value type, falling back to `value.getClass()` otherwise. The existing adaptation path for object array types is therefore preserved, and all primitive array types now accept a single value. The accompanying test covers single-value wrapping for every array type declared by ArrayTypes. Closes spring-projectsgh-37349 Signed-off-by: Chengang Guan <guanchengang@qq.com>
sbrannen
force-pushed
the
fix/single-value-primitive-array-adaptation
branch
from
September 30, 2026 11:35
b8e2b64 to
6774270
Compare
Contributor
|
Fixed via 6afb65b |
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this pull request
Sep 30, 2026
This commit adds a test to MergedAnnotationsTests that verifies a single primitive attribute in a composed annotation can be aliased via @AliasFor to a primitive array attribute in a meta-annotation. See spring-projectsgh-37349
Member
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.
This branch appears to handle the single-value to array case when using
TypeMappedAnnotation.of(classLoader, source, annotationType,attributes)with a Map. However, due to primitive boxing/unboxing, it only works for object array types such asString,Class,enum, andannotationarrays.
For primitive array types,
value.getClass()returns the boxed type, soArray.newInstance(value.getClass(), 1)produces a boxed array rather than a primitive array. The subsequent compatibility check then fails and throws anIllegalStateException.
Checking whether the value can be unboxed to the component type of the primitive array would let this branch handle all primitive array types on equal footing.