Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3396

groovy ant task fails at instanciating class that has no standard constructor

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Won't Fix
    • 1.6
    • None
    • Ant integration
    • None
    • Windows XP
      Groovy Version: 1.6.0 JVM: 1.5.0_17
      Apache Ant version 1.7.0 compiled on December 13 2006

    Description

      Given a class that contains a main method and a constructor. The constructor is non-standard, i.e. requires one or more arguments. The main method creates an instance of the class using the constructor with arguments.

      Using Groovy to execute that class works fine.
      Using the groovy ant task, however, ends in an Exception.
      Groovy script and ant script for triggering the error are attached.
      When specifying a default constructor as well, the example works again in ant.

      Output:

      Apache Ant version 1.7.0 compiled on December 13 2006
      Buildfile: build.xml
      Detected Java version: 1.5 in: C:\Programme\Java\jdk1.5.0_17\jre
      Detected OS: Windows XP
      parsing buildfile C:\Dokumente und Einstellungen\roeh_al\Desktop\failgroovy\build.xml with URI = file:/C:/Dokumente%20und%20Einstellungen/roeh_al/Desktop/failgroovy/build.xml
      Project base dir set to: C:\Dokumente und Einstellungen\roeh_al\Desktop\failgroovy
      [antlib:org.apache.tools.ant] Could not load definitions from resource org/apache/tools/ant/antlib.xml. It could not be found.
      Build sequence for target(s) `failgroovy' is [failgroovy]
      Complete build sequence is [failgroovy, ]

      failgroovy:
      [groovy] Script: class test {
      [groovy]
      [groovy] public test( text )

      { [groovy] println text [groovy] }

      [groovy]
      [groovy] static main(args)

      { [groovy] def t = new test("hello") [groovy] }

      [groovy] }
      [groovy]

      BUILD FAILED
      C:\Dokumente und Einstellungen\roeh_al\Desktop\failgroovy\build.xml:7: groovy.lang.GroovyRuntimeException: Failed to create Script instance for class: class test. Reason: java.lang.InstantiationException: test
      at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:115)
      at org.apache.tools.ant.Task.perform(Task.java:348)
      at org.apache.tools.ant.Target.execute(Target.java:357)
      at org.apache.tools.ant.Target.performTasks(Target.java:385)
      at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
      at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
      at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
      at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
      at org.apache.tools.ant.Main.runBuild(Main.java:698)
      at org.apache.tools.ant.Main.startAnt(Main.java:199)
      at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
      at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
      Caused by: groovy.lang.GroovyRuntimeException: Failed to create Script instance for class: class test. Reason: java.lang.InstantiationException: test
      at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:412)
      at groovy.lang.GroovyShell.parse(GroovyShell.java:602)
      at groovy.lang.GroovyShell.parse(GroovyShell.java:582)
      at groovy.lang.GroovyShell.parse(GroovyShell.java:629)
      at org.codehaus.groovy.ant.Groovy.parseAndRunScript(Groovy.java:413)
      at org.codehaus.groovy.ant.Groovy.execGroovy(Groovy.java:404)
      at org.codehaus.groovy.ant.Groovy.execute(Groovy.java:279)
      at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
      ... 11 more
      Caused by: java.lang.InstantiationException: test
      at java.lang.Class.newInstance0(Class.java:335)
      at java.lang.Class.newInstance(Class.java:303)
      at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:395)
      ... 23 more
      — Nested Exception —
      groovy.lang.GroovyRuntimeException: Failed to create Script instance for class:
      class test. Reason: java.lang.InstantiationException: test
      at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:412)
      at groovy.lang.GroovyShell.parse(GroovyShell.java:602)
      at groovy.lang.GroovyShell.parse(GroovyShell.java:582)
      at groovy.lang.GroovyShell.parse(GroovyShell.java:629)
      at org.codehaus.groovy.ant.Groovy.parseAndRunScript(Groovy.java:413)
      at org.codehaus.groovy.ant.Groovy.execGroovy(Groovy.java:404)
      at org.codehaus.groovy.ant.Groovy.execute(Groovy.java:279)
      at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
      at org.apache.tools.ant.Task.perform(Task.java:348)
      at org.apache.tools.ant.Target.execute(Target.java:357)
      at org.apache.tools.ant.Target.performTasks(Target.java:385)
      at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
      at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
      at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
      at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
      at org.apache.tools.ant.Main.runBuild(Main.java:698)
      at org.apache.tools.ant.Main.startAnt(Main.java:199)
      at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
      at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
      Caused by: java.lang.InstantiationException: test
      at java.lang.Class.newInstance0(Class.java:335)
      at java.lang.Class.newInstance(Class.java:303)
      at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:395)
      ... 23 more

      Total time: 2 seconds

      Attachments

        1. 3396_v16x.txt
          2 kB
          Roshan Dawrani
        2. test.groovy
          0.1 kB
          Alexander Röhnsch
        3. build.xml
          0.3 kB
          Alexander Röhnsch

        Activity

          People

            Unassigned Unassigned
            hetu Alexander Röhnsch
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: