Hi,
I'm having a problem using the 'trycatch' task defined by TryCatchTask.java from the
SourceForge 'antcontrib' project. However, I don't know if this problem is particular
to that task or custom tasks in general. The problem is a bit deep inside ant for me
to figure out. Perhaps someone came across something similar while developing or using
a custom task and can save me some time by pointing me in the right direction.
The problem is that ant is throwing a null pointer exception. This happens in the
class UnknownElement when trying to create a task object for the task in the
trycatch's 'try' clause. It seems that the project object never gets set and so the
line 'project.createTask()' throws the NullPointerException.
I'm using ant 1.4.1 and JDK 1.3.1_01 under Solaris
To isolate the problem, I created a build.xml that has only the code sample from the
TryCatchTask javadoc:
<project name="Test TryCatchTask" default="test.it">
<target name="test.it">
<taskdef name="trycatch" classname="net.sf.antcontrib.logic.TryCatchTask"/>
<trycatch property="foo" reference="bar">
<try>
<fail>Tada!</fail>
</try>
<catch>
<echo>In <catch>.</echo>
</catch>
<finally>
<echo>In <finally>.</echo>
</finally>
</trycatch>
</target>
</project>
I added the following debugging lines to the beginning of the makeTask() method in
UnknownElement.java
protected Task makeTask(UnknownElement ue, RuntimeConfigurable w) {
System.out.println("-------");
System.out.println("ue: " + ue);
System.out.println("ue.getTag(): " + ue.getTag());
System.out.println("project: " + project);
System.out.println("project.getName(): " + project.getName());
Task task = project.createTask(ue.getTag());
System.out.println("task: " + task);
When run, I get the following output:
msexter ~/AutoDeploy$ ant -verbose
Ant version 1.4.1 compiled on October 11 2001
Buildfile: build.xml
Detected Java version: 1.3 in: /usr/j2sdk1_3_1_01/jre
Detected OS: SunOS
parsing buildfile /private/msexter/AutoDeploy/build.xml with URI = file:/private
/msexter/AutoDeploy/build.xml
Project base dir set to: /private/msexter/AutoDeploy
Build sequence for target `test.it' is [test.it]
Complete build sequence is [test.it]
test.it:
[trycatch] -------
[trycatch] ue: org.apache.tools.ant.UnknownElement@2d7a10
[trycatch] ue.getTag(): trycatch
[trycatch] project: org.apache.tools.ant.Project@93efe
[trycatch] project.getName(): Test TryCatchTask
[trycatch] task: net.sf.antcontrib.logic.TryCatchTask@28c488
[trycatch] -------
[trycatch] ue: org.apache.tools.ant.UnknownElement@48cc8c
[trycatch] ue.getTag(): fail
[trycatch] project: null
BUILD FAILED
java.lang.NullPointerException
at org.apache.tools.ant.UnknownElement.makeTask(UnknownElement.java:156)
<-really line 148
at org.apache.tools.ant.UnknownElement.handleChildren(UnknownElement.java:127)
at org.apache.tools.ant.UnknownElement.handleChildren(UnknownElement.java:137)
at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:88)
at org.apache.tools.ant.Task.perform(Task.java:216)
at org.apache.tools.ant.Target.execute(Target.java:184)
at org.apache.tools.ant.Target.performTasks(Target.java:202)
at org.apache.tools.ant.Project.executeTarget(Project.java:601)
at org.apache.tools.ant.Project.executeTargets(Project.java:560)
at org.apache.tools.ant.Main.runBuild(Main.java:454)
at org.apache.tools.ant.Main.start(Main.java:153)
at org.apache.tools.ant.Main.main(Main.java:176)
Total time: 1 second
I don't think this is a classpath problem since the TryCatchTask object is
successfully created and ant doesn't barf until it tries to create a task object for
the nested tasks. Any help you could give would be appreciated...
- Mike
----------
Mike Sexter
(650)633-8603
Principal Member of Technical Staff
<http://www.oraclemobile.com/>OracleMobile - Online Studio
http://msexter.tripod.com