This commit fixes issue #33212.

Context:

Previously, attempting to convert a primitive array to an Object array caused a java.lang.ClassCastException.

This happened because the check to bypass array conversion only checked if the types of the array elements were convertible. This is not sufficient to determine if two arrays are convertible, because—while an int can be cast to an Integer—an int[] cannot be cast to an Integer[].

Solution

This commit fixes the issue by only bypassing conversion for arrays if one of the following conditions is true: - the source and target array elements have the same primitive type - the source and target array elements have non-primitive types

Comments

This is my first contribution so please feel free to make suggestions. I moved the boolean logic into a separate function to improve code clarity, but I'm happy to inline the logic to improve performance.

Comment From: snicoll

@mcvayc thanks for the PR but the issue is already assigned so we can't accept this contribution. Going forward, please ask before starting the implementation.

Comment From: sbrannen

Hi @mcvayc,

In case you're interested in the approach I took to address this issue, see commit https://github.com/spring-projects/spring-framework/commit/cb6a5baac508921486fd13a7a91cab9d7625868b.

Regards,

Sam

Comment From: mcvayc

Thanks, @sbrannen, that is simpler.