Hi all,
When I'm using Ant 1.6.1 in Netbeans 3.6 to execute one of the emma-tasks (see: emma.sourceforge.net), I'm seeing the following stacktrace:
<preceding tasks left out....> instrument: java.lang.NullPointerException at org.apache.tools.ant.Project.getThreadTask(Project.java:1985) at org.apache.tools.ant.Project.demuxFlush(Project.java:1155) at org.apache.tools.ant.DemuxOutputStream.processFlush(DemuxOutputStream.java:186) at org.apache.tools.ant.DemuxOutputStream.flush(DemuxOutputStream.java:211) at java.io.PrintStream.flush(PrintStream.java:136) at sun.nio.cs.StreamEncoder$CharsetSE.implFlush(StreamEncoder.java:410) at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:152) at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:213) at java.io.BufferedWriter.flush(BufferedWriter.java:230) at java.io.PrintWriter.flush(PrintWriter.java:120) at com.vladium.logging.Logger.cleanup(Logger.java:436) at com.vladium.logging.Logger.pop(Logger.java:364) at com.vladium.emma.Processor.run(Processor.java:60) at com.vladium.emma.instr.instrTask.execute(instrTask.java:77) at com.vladium.emma.emmaTask.execute(emmaTask.java:57) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:269) at org.apache.tools.ant.Task.perform(Task.java:364) at org.apache.tools.ant.Target.execute(Target.java:301) at org.apache.tools.ant.Target.performTasks(Target.java:328) at org.apache.tools.ant.Project.executeTarget(Project.java:1215) at org.apache.tools.ant.Project.executeTargets(Project.java:1063) at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:178) at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:252) at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:125)
This seems to happen only in Netbeans, not when I'm calling ANT (1.6.0, or 1.6.2) from the commandline. (didn't try 1.6.1)
The relevant section in oata.Project is:
/** * Get the current task associated with a thread, if any * * @param thread the thread for which the task is required. * @return the task which is currently registered for the given thread or * null if no task is registered. */ public Task getThreadTask(Thread thread) { Task task = (Task) threadTasks.get(thread); <--- NPE occurs here. if (task == null) { ThreadGroup group = thread.getThreadGroup(); while (task == null && group != null) { task = (Task) threadGroupTasks.get(group); group = group.getParent(); } } return task; }
Fixing this to read. public Task getThreadTask(Thread thread) { Object task = threadTasks.get(thread); // <-- removed cast if (task == null) { ThreadGroup group = thread.getThreadGroup(); while (task == null && group != null) { task = (Task) threadGroupTasks.get(group); // ???? group = group.getParent(); } } return (Task) task; // <-- inserted cast }
Solved the problem for me. Looks to me, as if somebody was aware, that the threadTask.get() might return null, but misplaced the cast to java.lang.Task.
As a side thought, I'm wondering, wether this might happen to threadGroupTask.get() also, so it would be better to remove the cast there also....
Btw, I checked the most current source (1.7 alpha?) also, it seemed to be unchanged in this respect, so a patch would be applicable for all sources from 1.6.1 up to now, maybe even earlier.
Cheers! Thomas
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]