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

Regression in handling of overloaded setters / properties between Spring 5.x and 6.x #34037

Closed
Spikhalskiy opened this issue Dec 5, 2024 · 2 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: invalid An issue that we don't feel is valid

Comments

@Spikhalskiy
Copy link

Spikhalskiy commented Dec 5, 2024

    <bean id="someProxyServerBuilder" class="org.asynchttpclient.proxy.ProxyServer.Builder">
        <property name="realm">
            <bean factory-bean="someRealmBuilder" factory-method="build"/>
        </property>
    </bean>
    
    <bean id="someRealmBuilder" class="org.asynchttpclient.Realm.Builder">
    </bean>

This configuration works successfully in Spring 5.x, but fails with Spring 6.x with the following error:

Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.asynchttpclient.Realm' to required type 'org.asynchttpclient.Realm$Builder' for property 'realm'; Cannot convert value of type 'org.asynchttpclient.Realm' to required type 'org.asynchttpclient.Realm$Builder' for property 'realm': no matching editors or conversion strategy found
	at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:594)
	at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:608)
	at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:190)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1728)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1685)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1429)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
	... 107 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type 'org.asynchttpclient.Realm' to required type 'org.asynchttpclient.Realm$Builder' for property 'realm': no matching editors or conversion strategy found
	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:260)
	at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:589)
	... 113 more

The complexity comes from the fact that org.asynchttpclient.proxy.ProxyServer.Builder#setRealm is overloaded, and there are two versions—one accepting Realm and another accepting Realm$Builder.

The following code in BeanWrapperImpl seems like it's not considering there may be several property descriptors for the same name:

https://github.com/spring-projects/spring-framework/blob/2e57603/spring-beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java#L184

PropertyDescriptor pd = cachedIntrospectionResults.getPropertyDescriptor(propertyName);

What makes the matter worse, looks like the behavior is not deterministic. In different environments Spring will try to use different setters.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 5, 2024
@bclozel bclozel added the in: core Issues in core modules (aop, beans, core, context, expression) label Dec 6, 2024
@jhoeller
Copy link
Contributor

jhoeller commented Dec 6, 2024

Which version have you tried this with specifically? As of 6.1.4, there is a dedicated write method fallback mechanism that should cover such overloaded setter scenarios: see #31872 and #32159.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Dec 6, 2024
@Spikhalskiy
Copy link
Author

@jhoeller it's 6.0.23; we are making baby steps in migrating from Spring 5. Taking into account that 6.0 is EOL, I will reopen if the issue I still present on the latest 6.1. Thank you for the context!

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Dec 6, 2024
@bclozel bclozel added status: invalid An issue that we don't feel is valid and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 6, 2024
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) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

5 participants