mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
OptionalToObjectConverter.matches() used TypeDescriptor.getElementTypeDescriptor(), which returns null for an Optional (element types are only resolved for arrays, streams and collections). ConversionUtils.canConvertElements() then treats a null source element type as "maybe" and returns true unconditionally, so ConversionService.canConvert(Optional<X>, target) reported true even when X is not convertible to the target -- a violation of the canConvert contract, since the subsequent conversion fails. To address that, this commit resolves the Optional's element type from its generic and checks it against the target, mirroring ObjectToOptionalConverter. A raw or otherwise unresolved element type remains permissive. Closes gh-36913 Signed-off-by: junhyeong9812 <pickjog@gmail.com>