Bug 50894 - Invoking multiple targets that share the same dependency to augment a path causes NullPointerException
Summary: Invoking multiple targets that share the same dependency to augment a path ca...
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.8.2
Hardware: PC Windows XP
: P2 critical with 1 vote (vote)
Target Milestone: 1.8.3
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-08 13:45 UTC by rich
Modified: 2012-01-19 13:57 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description rich 2011-03-08 13:45:14 UTC
Using this build file:

<project>

    <target name="foo" depends="aug">
        <echo message="${toString:p}" />
    </target>

    <target name="bar" depends="aug">
        <echo message="${toString:p}" />
    </target>

    <path id="p" />

    <target name="aug">
        <augment id="p">
            <path>
                <pathelement path="/" />
            </path>
        </augment>
    </target>

</project>

I can invoke each target, foo and bar, independently; for example

ant foo
Buildfile: C:\dev\projects\ant-playground\augment-with-multiple-target\build.xml

aug:

foo:
     [echo] C:\

BUILD SUCCESSFUL

ant bar
Buildfile: C:\dev\projects\ant-playground\augment-with-multiple-target\build.xml

aug:

bar:
     [echo] C:\

BUILD SUCCESSFUL

However, invoking both on the same command line causes an error:

ant foo bar
Buildfile: C:\dev\projects\ant-playground\augment-with-multiple-target\build.xml

aug:

foo:
     [echo] C:\

aug:

BUILD FAILED
C:\dev\projects\ant-playground\augment-with-multiple-targets\build.xml:14: java.lang.NullPointerException
        at org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:376)
        at org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:344)
        at org.apache.tools.ant.Task.maybeConfigure(Task.java:202)
        at org.apache.tools.ant.Task.perform(Task.java:347)
        at org.apache.tools.ant.Target.execute(Target.java:390)
        at org.apache.tools.ant.Target.performTasks(Target.java:411)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.Main.runBuild(Main.java:809)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

If foo and bar independently use augment, even for the same path (that is, they don't use depends on a shared target) like this:

<project>

    <target name="foo">
        <augment id="p">
            <path>
                <pathelement path="/" />
            </path>
        </augment>
        <echo message="${toString:p}" />
    </target>

    <target name="bar">
        <augment id="p">
            <path>
                <pathelement path="/" />
            </path>
        </augment>
        <echo message="${toString:p}" />
    </target>

    <path id="p" />

</project>

the build works.

Needless to say, trying to retrain everyone to avoid using multiple targets on the command line is proving to be difficult.
Comment 1 Stefan Bodewig 2011-07-27 14:08:28 UTC
fixed with svn revision 1151473

The patch should work standalone with Ant 1.8.2 as well.