groovy
  1. groovy
  2. GROOVY-1506

groovy task in ant throws NPE when calling target from inside groovy with antcall

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0-JSR-6
    • Fix Version/s: 1.0-RC-1
    • Component/s: Ant integration
    • Labels:
      None
    • Number of attachments :
      2

      Description

      Please see the attached build.xml. I am using groovy from svn main trunk rev. 4066, which is installed in ./lib
      The output is:
      Buildfile: build.xml

      main:

      sub:
      [echo] Hello
      [echo] in groovy

      BUILD FAILED
      : java.lang.NullPointerException

      Total time: 7 seconds

      starting with ant -d I get the following stack trace:
      : java.lang.NullPointerException
      at org.apache.tools.ant.Task.perform(Task.java:373)
      at groovy.util.AntBuilder.nodeCompleted(AntBuilder.java:178)
      at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:175)
      at groovy.util.AntBuilder.doInvokeMethod(AntBuilder.java:139)
      at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:86)
      at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:164)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:80)
      at Script1.run(Script1.groovy:2)
      at org.codehaus.groovy.ant.Groovy.execGroovy(Groovy.java:369)
      at org.codehaus.groovy.ant.Groovy.execute(Groovy.java:259)
      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.executeSortedTargets(Project.java:1216)
      at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
      at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
      at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
      at org.apache.tools.ant.Main.runBuild(Main.java:668)
      at org.apache.tools.ant.Main.startAnt(Main.java:187)
      at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
      at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
      Caused by: java.lang.NullPointerException
      at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:321)
      at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:107)
      at org.apache.tools.ant.Task.perform(Task.java:364)
      ... 22 more
      — Nested Exception —
      java.lang.NullPointerException
      at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:321)
      at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:107)
      at org.apache.tools.ant.Task.perform(Task.java:364)
      at groovy.util.AntBuilder.nodeCompleted(AntBuilder.java:178)
      at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:175)
      at groovy.util.AntBuilder.doInvokeMethod(AntBuilder.java:139)
      at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:86)
      at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:164)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:80)
      at Script1.run(Script1.groovy:2)
      at org.codehaus.groovy.ant.Groovy.execGroovy(Groovy.java:369)
      at org.codehaus.groovy.ant.Groovy.execute(Groovy.java:259)
      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.executeSortedTargets(Project.java:1216)
      at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
      at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
      at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
      at org.apache.tools.ant.Main.runBuild(Main.java:668)
      at org.apache.tools.ant.Main.startAnt(Main.java:187)
      at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
      at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)

      Total time: 8 seconds

      1. antcall-from-groovy-task.patch
        2 kB
        Andreas Sahlbach
      2. build.xml
        0.6 kB
        Andreas Sahlbach

        Activity

        Hide
        Andreas Sahlbach added a comment -

        Hi, I think I found it. The problem is, that the AntBuilder creates a collectorTarget as root target, so his child tasks will have an owning target. Unfortunately the antcall target needs a root target with a name property that is not null. The name of the collectorTarget is null and this causes the NPE.
        The funny thing is, that this "fake" root target is not needed when calling antcall within an ant task, because the groovy task actually has an owning target with a proper name. The groovy task just does not give it properly to the antbuilder.
        So I introduced a new Constructor that allows just this and modified the code in the Groovy task to use it. The code should be backward compatible.
        I tried to write a test case for this but failed. The reason is that all tests are based on Groovy Tests and this NPE does not appear when the ant task is called from the context of Groovy. It only fails if it is called from ant (I checked this with my test case, calling it from the test suite and from pure ant).

        Show
        Andreas Sahlbach added a comment - Hi, I think I found it. The problem is, that the AntBuilder creates a collectorTarget as root target, so his child tasks will have an owning target. Unfortunately the antcall target needs a root target with a name property that is not null. The name of the collectorTarget is null and this causes the NPE. The funny thing is, that this "fake" root target is not needed when calling antcall within an ant task, because the groovy task actually has an owning target with a proper name. The groovy task just does not give it properly to the antbuilder. So I introduced a new Constructor that allows just this and modified the code in the Groovy task to use it. The code should be backward compatible. I tried to write a test case for this but failed. The reason is that all tests are based on Groovy Tests and this NPE does not appear when the ant task is called from the context of Groovy. It only fails if it is called from ant (I checked this with my test case, calling it from the test suite and from pure ant).
        Hide
        Guillaume Laforge added a comment -

        Thanks a lot for your patch Andreas.

        Show
        Guillaume Laforge added a comment - Thanks a lot for your patch Andreas.

          People

          • Assignee:
            Guillaume Laforge
            Reporter:
            Andreas Sahlbach
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: