You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bu...@apache.org on 2008/02/27 06:18:43 UTC

[Bug 40641] UnknownElement.maybeConfigure() is really "always configure"

http://issues.apache.org/bugzilla/show_bug.cgi?id=40641





--- Comment #6 from Keith D Gregory <kd...@yahoo.com>  2006-09-29 15:53:52 ---
Although the documentation indicates that this method will only configure a task
if it has not already been configured, the actual code always creates a new
object, and always calls configure() with that new object.

Aside from not following the documentation, this makes any sort of parent-child
dependency injection impossible. Consider the following:

    for (Task child : _children) {
        child.maybeConfigure();
        if (child instanceof UnknownElement) {
            Object realThing = ((UnknownElement)child).getRealThing();
            if (realThing instanceof MyTask) {
                ((MyTask)realThing).injectParent(this);
            }
        }
        child.perform();
    }

When I explicitly call maybeConfigure() on the child, assuming that the parent
hasn't been executed already, I expect it to create an actual child instance. I
then inject the dependency (ugly though that may be), and perform the task. I
know that perform() will also call maybeConfigure(), but according to the
documentation, it should only do something "if it hasn't been done already".
Instead, it replaces the "real thing" with a new instance, and I get a NPE when
I try to access the parent.

One alternative is to create the children explicitly, via factory methods on the
parent. However, these children will be configured _before the parent is run_,
which means that I can't rely on property conversions (since they property is
still "${foo}" at this point, and have to explicitly convert the properties at
runtime.

Another alternative (and I'll add an enhancement request for this if it's not in
the 1.7 beta docs) is to allow dependency injection as part of the Task interface.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.