-
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
With XML configuration, setter selection can be random in case of overloaded setter methods (e.g. on SimpleClientHttpRequestFactory in 6.1) #31872
Comments
Could you share a minimal sample project that demonstrates the problem? Can you replicate the issue with 6.1.0-M1 as well? This could be linked to #29559 and this note about parameter name retention in the upgrade guide. It doesn't look like httpcomponents is compiling their code with the |
In contrast to the sibling issue about constructor arguments, this one is not actually related to parameter name retention as far as I can tell. This is rather a consequence of us having added overloaded setter methods to While we arguably should have introduced those Duration-based setters with different method names instead, as traditional JavaBeans wants it to be if the argument types differ, there is also a long-standing case that we should handle this in a more lenient but predictable fashion. I'll see what I can do about this for 6.1.3. |
This is still reproducible for me exactly with the same XML Bean definition on 6.1.3 version. According to stack trace the exception (TypeMismatchException) is happening here Line 1689 in 2e9d6a1
As far as I understand the fix by @jhoeller will help if convertIfNecessary method is called later @ Line 1717 in 2e9d6a1
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) Any suggestions? |
@dima-sarin good catch, we should be equally defensive when pre-converting a value there, sorry for missing this the first time around. Could you please create a follow-up GitHub issue linking to this one? I'll revisit this for 6.1.4 then. |
Affects: 6.1.0-M2 or later
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.
I think this behavior is a bug in Spring Framework, what do you think?
Detail
I found this behavior in the bean definition of SimpleClientHttpRequestFactory.
Here is an example of a Baen definition.
spring-web-6.1.0-M2 or later,
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 behavior was that a Duration setter would be used.
However, in actuality, the int setter was sometimes used.
The log of that case is shown below.
log.txt
The text was updated successfully, but these errors were encountered: