Bug 31840 - NPE using XmlLogger and antlib
Summary: NPE using XmlLogger and antlib
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.6.2
Hardware: Other other
: P3 critical (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-21 23:59 UTC by Mariano Benitez
Modified: 2008-02-22 12:18 UTC (History)
1 user (show)



Attachments
invoking build (163 bytes, text/plain)
2004-10-22 00:00 UTC, Mariano Benitez
Details
simple antlib (163 bytes, text/plain)
2004-10-22 00:01 UTC, Mariano Benitez
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mariano Benitez 2004-10-21 23:59:54 UTC
I put down the problem to a simple procedure to reproduce:
I have sample.xml and antlib.xml, I just define the antlib in sample.xml and
when I try to run it with the XmlLogger I get this:

mariano@fenix:/w/MAIN/local/modules/boot.launcher> ant -f sample.xml -logger
org.apache.tools.ant.XmlLogger
Buildfile: sample.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="log.xsl"?>

<build time="0 seconds" error="/w/MAIN/local/modules/boot.launcher/sample.xml:5:
srcdir attribute must be set!">
        <task name="java.lang.NullPointerException
        at
org.apache.tools.ant.util.DOMElementWriter.encode(DOMElementWriter.java:174)
        at
org.apache.tools.ant.util.DOMElementWriter.write(DOMElementWriter.java:95)
        at
org.apache.tools.ant.util.DOMElementWriter.write(DOMElementWriter.java:113)
        at org.apache.tools.ant.XmlLogger.buildFinished(XmlLogger.java:189)
        at org.apache.tools.ant.Project.fireBuildFinished(Project.java:1796)
        at org.apache.tools.ant.Main.runBuild(Main.java:693)
        at org.apache.tools.ant.Main.startAnt(Main.java:188)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)


this happens because the antlib taskname is null, I debugged it and found that
the taskname attribute of the antlib is never defined. and when the logger
receives the taskStarted for the antlib, it stores a null for the value, and
that breaks the XmlLogger.

I really need this to be able to use CruiseControl with our ant project, since
it uses it extensively as I understand.
Comment 1 Mariano Benitez 2004-10-22 00:00:40 UTC
Created attachment 13173 [details]
invoking build
Comment 2 Mariano Benitez 2004-10-22 00:01:05 UTC
Created attachment 13174 [details]
simple antlib
Comment 3 Peter Reilly 2004-10-22 16:58:19 UTC
This is stange. I cannot reproduce the problem
with the build.xml and antlib.xml files given.

I tested with ant1.6.0, ant1.6.1 and ant1.6.2.

The output given was:
ant -f build.xml -logger org.apache.tools.ant.XmlLogger
Buildfile: build.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="log.xsl"?>

<build error="/home/preilly/learning/a/antlib/error/build.xml:5: srcdir
attribute must be set!" time="0 seconds">
        <task location="/home/preilly/learning/a/antlib/error/antlib.xml:2: "
name="" time="0 seconds"></task>
        <task location="/home/preilly/learning/a/antlib/error/build.xml:3: "
name="typedef" time="0 seconds"></task>
        <target name="build" time="0 seconds">
                <task
location="/home/preilly/learning/a/antlib/error/build.xml:5: " name="javac2"
time="0 seconds"></task>
        </target>
        <stacktrace><![CDATA[/home/preilly/learning/a/antlib/error/build.xml:5:
srcdir attribute must be set!
        at org.apache.tools.ant.taskdefs.Javac.checkParameters(Javac.java:893)
        at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:738)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
        at org.apache.tools.ant.Task.perform(Task.java:364)
        at org.apache.tools.ant.Target.execute(Target.java:341)
        at org.apache.tools.ant.Target.performTasks(Target.java:369)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
        at org.apache.tools.ant.Main.runBuild(Main.java:673)
        at org.apache.tools.ant.Main.startAnt(Main.java:188)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
]]></stacktrace>
</build>
Comment 4 Mariano Benitez 2004-10-22 17:37:59 UTC
well, it did happen to me, the problem is that the build file is wrong, fix it
ant it should break.
I am using jdk 1.4.2_05, if that helps.
Comment 5 Mariano Benitez 2004-10-22 17:40:46 UTC
this is the output with a patch to make Antlib.java return "antlib" as taskname

mariano@fenix:/w/MAIN/local/lib/eclipse> ant -f sample.xml -logger
org.apache.tools.ant.XmlLogger
Buildfile: sample.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="log.xsl"?>

<build time="0 seconds" error="/w/MAIN/local/lib/eclipse/sample.xml:5: srcdir
attribute must be set!">
        <task name="antlib" location="/w/MAIN/local/lib/eclipse/antlib.xml:2: "
time="0 seconds"></task>
        <task name="typedef" location="/w/MAIN/local/lib/eclipse/sample.xml:3: "
time="0 seconds"></task>
        <target name="build" time="0 seconds">
                <task name="javac2"
location="/w/MAIN/local/lib/eclipse/sample.xml:5: " time="0 seconds"></task>
        </target>
        <stacktrace><![CDATA[/w/MAIN/local/lib/eclipse/sample.xml:5: srcdir
attribute must be set!
        at org.apache.tools.ant.taskdefs.Javac.checkParameters(Javac.java:893)
        at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:738)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
        at org.apache.tools.ant.Task.perform(Task.java:364)
        at org.apache.tools.ant.Target.execute(Target.java:341)
        at org.apache.tools.ant.Target.performTasks(Target.java:369)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
        at org.apache.tools.ant.Main.runBuild(Main.java:673)
        at org.apache.tools.ant.Main.startAnt(Main.java:188)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
]]></stacktrace>
</build>
Comment 6 Mariano Benitez 2004-10-22 17:42:19 UTC
maybe a difference in XML parsers, probably your parser returns "" when no
attribute is defined, and mine returns null?
your task name in the "antlib" element in the output is "", since mine is null,
it breaks.
Comment 7 Mariano Benitez 2004-10-22 17:45:11 UTC
java -version:
---------------------------
java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)

on Linux SuSE 9.1 i686
Comment 8 Peter Reilly 2004-10-26 08:42:37 UTC
Can you post the patch for Antlib.java.
I now see the "" in the  name for the antlib task. There
could be a difference in the XML or something. I had
though that the problem was the "java2" name.
Comment 9 Mariano Benitez 2004-10-26 11:47:06 UTC
I guess adding getTaskName() { return "antlib"; } to Antlib.java is fine, but
should the logger handle properly this case, maybe some custom task is not
returning the proper value, and the logger will fail.

Are you ok to include also the handling of null in the logger?

Will post the patch, against which branch you want the patch to be created?
Comment 10 Peter Reilly 2004-10-26 12:04:26 UTC
Create the patch against CVS HEAD of ant.
Yes, the xml logger should be fixed to handle null pointer for
the task name.
Comment 11 Peter Reilly 2004-10-27 12:56:11 UTC
ok, I checked the code, and the value of the name attribute is
being set to null for antlib. There must be a difference
in the xml processors, as I do not see a null pointer exception,
but setting the value to null cannot be correct.
So, I have changed XmlLogger to check if the name is null and
set it to "" if it is.
Also, the name of the antlib task is being set to "antlib".
Changes are committed and will be in the next release of ant.

Thanks for the report, the nice test case and the follow up
comments.