Affects: 6.1.3
Summary In XMLConfig, if a bean-defined class has an overloaded setter, an exception may be thrown at runtime.
I checked the logs and found that the wrong setter was used. Specifically, I found that the setter was changing each time the application was launched.
This behavior only occurs in XMLConfig and not in JavaConfig.
Detail I found this behaviour in the bean definition of SimpleClientHttpRequestFactory. Here is an example of a Bean definition.
SimplyClientHttpRequestFactory have overload setter of Duration and int such as setConnectTimeout method, setReadTimeout method.
https://github.com/spring-projects/spring-framework/blob/v6.1.0-M2/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java#L99C1-L135C3
In the XMLConfig example above, my expected behaviour was that a Duration setter would be used. However, in actuality, the int setter was sometimes used.
According to stack trace the exception (TypeMismatchException) is happening here https://github.com/spring-projects/spring-framework/blob/2e9d6a1d4e4720414ab3c5c0f64f9ff20cf676eb/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java#L1689
The fix by @jhoeller from https://github.com/spring-projects/spring-framework/issues/31872 will help if convertIfNecessary method is called later @ https://github.com/spring-projects/spring-framework/blob/2e9d6a1d4e4720414ab3c5c0f64f9ff20cf676eb/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java#L1717
Stack trace:
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.time.Duration' to required type 'int' for property 'connectTimeout'; Cannot convert value of type 'java.time.Duration' to required type 'int' for property 'connectTimeout': PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value of type 'java.time.Duration'
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:600)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:609)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:189)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1732)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1689)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1433)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598)
Comment From: jhoeller
This fix will be available in the upcoming 6.1.4 snapshot in case you'd like to give it an early try.