Skip to content

Non-deterministic behaviour of method injection [SPR-8351] #12998

@spring-projects-issues

Description

@spring-projects-issues

Szczepan Kuzniarz opened SPR-8351 and commented

Using lookup-method in child bean definition produces non-deterministic behaviour. In the following example:

public class Parent {
    public Object getSomething() {
        // method injection
        return null;
    }

    public void testMe() {
        System.out.println(getSomething());
    }
}
public class Child extends Parent {
}
public class ParentSomething {
    public String toString() {
        return "parent";
    }
}
public class ChildSomething {
    public String toString() {
        return "child";
    }
}
<bean id="parentSomething" class="ParentSomething"/>

<bean id="childSomething" class="ChildSomething"/>

<bean id="parentService" class="Parent">
    <lookup-method name="getSomething" bean="parentSomething"/>
</bean>

<bean id="childService" class="Child" parent="parentService">
    <lookup-method name="getSomething" bean="childSomething"/>
</bean>

the result of testMe method called on childService bean is random: in Spring 2.0.2 and earlier childService getSomething method is called, ane in Spring 2.0.3 and later parentService getSomething method is called. This is caused by MethodOverrides class storing MethodOveride instances in HashSet (which doesn't guarantee any particular order of elements). In my opinion the most specific lookup-method (childService in the example above) should be used.


Affects: 3.0.5

Issue Links:

Metadata

Metadata

Assignees

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