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.
Created attachment 13173 [details] invoking build
Created attachment 13174 [details] simple antlib
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>
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.
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>
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.
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
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.
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?
Create the patch against CVS HEAD of ant. Yes, the xml logger should be fixed to handle null pointer for the task name.
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.