Skip to content

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

@Spikhalskiy

Description

@Spikhalskiy
    <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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions