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

Custom base script abstract method throws NPE with the @BaseScript annotation on imports

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.0-beta-2
    • Fix Version/s: 2.3.0-rc-2
    • Component/s: None
    • Labels:
      None

      Description

      I was trying the custom abstract method for base scripts and encountered an NPE while using this variant with the base script class on imports:

      @BaseScript(CustomBase)
      import groovy.transform.BaseScript
      
      println 'Hello'
      
      abstract class CustomBase extends Script {
          def run() {
              before()
              internalRun()
              after()
          }
          
          abstract internalRun()
          
          def before() { println 'before' }
          def after()  { println 'after'  }
      }
      

      However, the version with the base script annotated local variable works:

      import groovy.transform.BaseScript
      
      @BaseScript CustomBase script
      
      println 'Hello'
      
      abstract class CustomBase extends Script {
          def run() {
              before()
              internalRun()
              after()
          }
          
          abstract internalRun()
          
          def before() { println 'before' }
          def after()  { println 'after'  }
      }
      

      The NPE I'm getting from within the Groovy Console is:

      BUG! exception in phase 'semantic analysis' in source unit 'basescript_custom_abstract_metod.groovy' unexpected NullpointerException
      	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1052)
      	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:583)
      	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:561)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:538)
      	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:286)
      	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:259)
      	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:674)
      	at groovy.lang.GroovyShell.run(GroovyShell.java:501)
      	at groovy.lang.GroovyShell.run(GroovyShell.java:481)
      	at groovy.lang.GroovyShell.run(GroovyShell.java:164)
      	at groovy.lang.GroovyShell$run$1.call(Unknown Source)
      	at groovy.ui.Console$_runScriptImpl_closure17.doCall(Console.groovy:977)
      	at groovy.ui.Console$_runScriptImpl_closure17.doCall(Console.groovy)
      	at sun.reflect.GeneratedMethodAccessor240.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:606)
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
      	at groovy.lang.Closure.call(Closure.java:423)
      	at groovy.lang.Closure.call(Closure.java:417)
      	at groovy.lang.Closure.run(Closure.java:504)
      	at java.lang.Thread.run(Thread.java:744)
      Caused by: java.lang.NullPointerException
      	at org.codehaus.groovy.ast.ClassNode.removeMethod(ClassNode.java:596)
      	at org.codehaus.groovy.transform.BaseScriptASTTransformation.changeBaseScriptType(BaseScriptASTTransformation.java:134)
      	at org.codehaus.groovy.transform.BaseScriptASTTransformation.changeBaseScriptTypeFromPackageOrImport(BaseScriptASTTransformation.java:78)
      	at org.codehaus.groovy.transform.BaseScriptASTTransformation.visit(BaseScriptASTTransformation.java:63)
      	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:1047)
      	... 23 more
      

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              guillaume Guillaume Sauthier
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: