You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ivy-user@ant.apache.org by osbald <ro...@hotmail.com> on 2008/03/11 19:22:50 UTC

Curious NullPointerExceptions from when invoked more than once?

Updated to beta2 today and I started seeing NPEs from the <ivy:settings>
setup. Oddly this only seems to kick-in if I invoke Ant with two targets
rather than calling Ant twice in succession. e.g. 'ant build test' fails
whereas 'ant build' followed by 'ant test' OK. 

Stacktrace was: 

java.lang.NullPointerException
        at org.apache.tools.ant.Task.perform(Task.java:357)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
        at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
        at org.apache.tools.ant.Main.runBuild(Main.java:698)
        at org.apache.tools.ant.Main.startAnt(Main.java:199)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: java.lang.NullPointerException
        at
org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:381)
        at
org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:349)
        at org.apache.tools.ant.Task.maybeConfigure(Task.java:202)
        at org.apache.tools.ant.Task.perform(Task.java:347)
        ... 10 more
--- Nested Exception ---
java.lang.NullPointerException
        at
org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:381)
        at
org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:349)
        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:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
        at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
        at org.apache.tools.ant.Main.runBuild(Main.java:698)
        at org.apache.tools.ant.Main.startAnt(Main.java:199)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

Although theres very little sign of Ivy in here. My build is roughly similar
to the modules one in that I've got a main script that calls out to module
scripts that each import a common script. The init target of the common
script is doing the ivy taskdef and settings. (if it dosent I get
forward/missing ivy.instance warnings). Something like:

<project name="main">
    
    <import file="common.xml"/>

    <target name="build-all" depends="init">
        <subant target="build" buildpathref="ivy-buildlist">
            <fileset dir="modules/" includes="*/build.xml"/>
        </subant>
    </target>
    
    <target name="test-all" depends="init">
        <subant target="test" buildpathref="ivy-buildlist">
            <fileset dir="modules/" includes="*/build.xml"/>
        </subant>
    </target>
    
</project>
 
---

<project name="common">
    
    <target name="init" depends="init.taskdefs">
        <ivy:settings id="ivy.instance" override="true"
file="ivysettings.xml"/>
    </target>

    <target name="init.taskdefs" unless="taskdefs.loaded">
        <taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant"
                 classpathref="project.build.classpath"/>
        <taskdef resource="net/sf/antcontrib/antlib.xml"
                 classpathref="project.build.classpath"/>
        <property name="taskdefs.loaded" value="true"/>
        <echo message="external taskdefs loaded."/>
    </target>
    
    <target name="build" depends="init">
    </target>

    <target name="test" depends="init">
    </target>
    
</project>

The problem kicks in when test calls init (after being invoked by test-all).
Wondering if this is an Ant or Ivy issue? beta1 didn't give me this problem,
only had to add override=true to my ivy:settings declaration when migrated
to beta2. I've been able to workaround the issue with ant-contrib conditions
around the init target - but it feels like a hack:

     <target name="init" depends="init.taskdefs">
        <if>
            <not><isset property="ivy.settings.file"/></not>
            <then>
                <ivy:settings id="ivy.instance" override="true"
                    file="ivysettings.xml"/>
            </then>
        </if>
    </target>

Relies on ivy.properties being set if <ivy:settings> have already been
called. Other option would be to forego chaining targets and code a combined
depends target for each combination (albeit less flexible).

-- 
View this message in context: http://www.nabble.com/Curious-NullPointerExceptions-from-%3Civy%3Asettings%3E-when-invoked-more-than-once--tp15983223p15983223.html
Sent from the ivy-user mailing list archive at Nabble.com.


Re: Curious NullPointerExceptions from when invoked more than once?

Posted by osbald <ro...@hotmail.com>.
Sorry - given the examples it'd be 'ant build-all test-all' that fails for me
(build & test targets only exist in module/common scripts). 
-- 
View this message in context: http://www.nabble.com/Curious-NullPointerExceptions-from-%3Civy%3Asettings%3E-when-invoked-more-than-once--tp15983223p15983476.html
Sent from the ivy-user mailing list archive at Nabble.com.