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

Ant groovyc throws a NoClassDefFoundError compiling a groovy class with @DelegatesTo and @CompileStatic

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1.4
    • 2.1.5
    • Static compilation
    • None
    • Windows 7, Java 6, Ant 1.8.2, Groovy 2.1.4

    Description

      I attached a sample project. The offending class is shown below. For some reason passing the closure inline triggers the error. The error goes away if I remove @CompileStatic, or declare the closure variable before passing it into method2. It also does not occur when compiling in IDEA, only with Ant.

      The error itself is easy to work around, but very difficult to identify since there is nothing in the error indicating what code triggered it.

      @groovy.transform.CompileStatic
      class MyClass {
          void method1() {
              method2({})
          }
      
          void method2(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = String) Closure body) {
      
          }
      }
      

      Stack trace:

      build.xml:24: java.lang.NoClassDefFoundError: groovy/lang/GroovyObject
              at java.lang.ClassLoader.defineClass1(Native Method)
              at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
              at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
              at groovy.lang.GroovyClassLoader.defineClass(GroovyClassLoader.java:504)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.evaluateExpression(StaticTypeCheckingSupport.java:1369)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallArguments(StaticTypeCheckingVisitor.java:1837)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallExpression(StaticTypeCheckingVisitor.java:2186)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethodCallExpression(StaticCompilationVisitor.java:220)
              at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:64)
              at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:69)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:193)
              at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:40)
              at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:35)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:163)
              at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:101)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:112)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitConstructorOrMethod(StaticTypeCheckingVisitor.java:1359)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:123)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:1634)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:1607)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethod(StaticCompilationVisitor.java:120)
              at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1055)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:172)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitClass(StaticCompilationVisitor.java:110)
              at org.codehaus.groovy.transform.sc.StaticCompileTransformation.visit(StaticCompileTransformation.java:60)
              at org.codehaus.groovy.transform.ASTTransformationVisitor.visitClass(ASTTransformationVisitor.java:132)
              at org.codehaus.groovy.transform.ASTTransformationVisitor$2.call(ASTTransformationVisitor.java:176)
              at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1036)
              at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:572)
              at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:550)
              at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:527)
              at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:506)
              at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:59)
              at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:215)
              at org.codehaus.groovy.ant.Groovyc.runCompiler(Groovyc.java:1103)
              at org.codehaus.groovy.ant.Groovyc.compile(Groovyc.java:1154)
              at org.codehaus.groovy.ant.Groovyc.execute(Groovyc.java:769)
              at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:601)
              at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
              at org.apache.tools.ant.Task.perform(Task.java:348)
              at org.apache.tools.ant.Target.execute(Target.java:390)
              at org.apache.tools.ant.Target.performTasks(Target.java:411)
              at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
              at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
              at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
              at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
              at org.apache.tools.ant.Main.runBuild(Main.java:809)
              at org.apache.tools.ant.Main.startAnt(Main.java:217)
              at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
              at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
      Caused by: java.lang.ClassNotFoundException: groovy.lang.GroovyObject
              at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
              at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
              at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:648)
              at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:758)
              at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:746)
              ... 56 more
      

      Attachments

        1. DelegatesToTest.zip
          5.44 MB
          Brett Borchardt

        Activity

          People

            melix C├ędric Champeau
            bborchardt Brett Borchardt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: