Skip to content
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

With XML configuration, setter selection can be random in case of overloaded setter methods (e.g. on SimpleClientHttpRequestFactory in 6.1.3 from convertForProperty method) #32159

Closed
dima-sarin opened this issue Jan 30, 2024 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@dima-sarin
Copy link

dima-sarin commented Jan 30, 2024

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

convertedValue = convertForProperty(resolvedValue, propertyName, bw, converter);

The fix by @jhoeller from #31872 will help if convertIfNecessary method is called later @

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)
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 30, 2024
@jhoeller jhoeller self-assigned this Jan 30, 2024
@jhoeller jhoeller added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 30, 2024
@jhoeller jhoeller added this to the 6.1.4 milestone Jan 30, 2024
@jhoeller jhoeller changed the title With XML configuration, setter selection can be random in case of overloaded setter methods (e.g. on SimpleClientHttpRequestFactory in 6.3 from convertForProperty method) With XML configuration, setter selection can be random in case of overloaded setter methods (e.g. on SimpleClientHttpRequestFactory in 6.1.3 from convertForProperty method) Jan 30, 2024
@jhoeller
Copy link
Contributor

This fix will be available in the upcoming 6.1.4 snapshot in case you'd like to give it an early try.

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) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants