-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConversionService
cannot convert primitive array to Object[]
#33212
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
Comments
sbrannen
added
the
in: core
Issues in core modules (aop, beans, core, context, expression)
label
Jul 13, 2024
mcvayc
pushed a commit
to mcvayc/spring-framework
that referenced
this issue
Jul 31, 2024
Convert if source and target types are not same primitive or non-primitive. Closes spring-projects#33212.
@sbrannen FTR, there was a PR reported against this that I've closed as you were already assigned. In case you haven't started anything and the PR addresses the issue, we can reconsider. |
github-actions
bot
added
status: backported
An issue that has been backported to maintenance branches
and removed
for: backport-to-6.0.x
labels
Aug 4, 2024
This was referenced Aug 4, 2024
sbrannen
added a commit
that referenced
this issue
Aug 5, 2024
Prior to this commit, the ConversionService failed to convert a primitive array (such as int[]) to an Object[] due to an error in the logic in ArrayToArrayConverter. This commit addresses this by augmenting the "can bypass conversion" check in ArrayToArrayConverter to ensure that the supplied source object is an instance of the target type (i.e., that the source array can be cast to the target type array without conversion). Closes gh-33212 (cherry picked from commit cb6a5ba)
sbrannen
added a commit
that referenced
this issue
Aug 5, 2024
Prior to this commit, the ConversionService failed to convert a primitive array (such as int[]) to an Object[] due to an error in the logic in ArrayToArrayConverter. This commit addresses this by augmenting the "can bypass conversion" check in ArrayToArrayConverter to ensure that the supplied source object is an instance of the target type (i.e., that the source array can be cast to the target type array without conversion). Closes gh-33212 (cherry picked from commit cb6a5ba) (cherry picked from commit 3e73724)
sbrannen
added a commit
that referenced
this issue
Aug 5, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Overview
The
DefaultConversionService
currently cannot convert a primitive array toObject[]
. This is due to the use ofGenericConversionService.canBypassConvert(...)
inArrayToArrayConverter
which assumes a conversion fromint[]
(or any other primitive array) toObject[]
is unnecessary because "anint
(or other primitive type) can be converted to anObject
by returning the source object unchanged," although the latter is not true for primitives.Thus an attempt to convert from
int[]
toObject[]
returns the sourceint[]
array unchanged and incompatible withObject[]
.This strikes me as a bit strange since the following conversions (and other similar conversions) are all supported. See the various
convert*()
test methods inDefaultConversionServiceTests
.int[]
-->Integer[]
int[]
-->String[]
int[]
-->float[]
Object[]
-->Integer[]
Object[]
-->int[]
The latter makes it clear that you can convert from
Object[]
toint[]
but not fromint[]
toObject[]
.Note that this also affects our varargs support in SpEL expressions. See the various
@Disabled
tests in ae5dd54 for examples.We should decide if we want to support conversions from primitive arrays to
Object[]
and otherwise consider documenting this as a known limitation.Related Issues
The text was updated successfully, but these errors were encountered: