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

BUG! exception in phase 'semantic analysis'... when trying to call instance method as default for a constructor parameter

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.3
    • 2.4.4
    • Compiler
    • None
    • Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
      Seen in java 7 too.

    Description

      % groovyc StaticDefault.groovy # the code below

      class StaticDefault {
          def name 
          StaticDefault(name = getName()) {
              this.name = name
          }
          private getName() {
              'name'
          }
      }
      

      And see this stacktrace:

      >>> a serious error occurred: BUG! exception in phase 'semantic analysis' in source unit 'StaticDefault.groovy' unexpected NullpointerException
      >>> stacktrace:
      BUG! exception in phase 'semantic analysis' in source unit 'StaticDefault.groovy' unexpected NullpointerException
      	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1057)
      	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:588)
      	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:566)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:543)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:522)
      	at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:59)
      	at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:215)
      	at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:148)
      	at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompileWithErrorHandling(FileSystemCompiler.java:178)
      	at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:162)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:483)
      	at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
      	at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)
      Caused by: java.lang.NullPointerException
      	at org.codehaus.groovy.control.StaticVerifier$1.visitVariableExpression(StaticVerifier.java:84)
      	at org.codehaus.groovy.ast.expr.VariableExpression.visit(VariableExpression.java:70)
      	at org.codehaus.groovy.ast.CodeVisitorSupport.visitMethodCallExpression(CodeVisitorSupport.java:129)
      	at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:64)
      	at org.codehaus.groovy.control.StaticVerifier.visitConstructorOrMethod(StaticVerifier.java:79)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructor(ClassCodeVisitorSupport.java:119)
      	at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1079)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
      	at org.codehaus.groovy.control.StaticVerifier.visitClass(StaticVerifier.java:42)
      	at org.codehaus.groovy.control.CompilationUnit$6.call(CompilationUnit.java:209)
      	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1052)
      	... 15 more
      

      Switching the method used for the default to a static method (private static getName()...)fixes the problem, but I'm guessing you likely wanted to give a better message out of the compiler.

      Attachments

        Activity

          People

            paulk Paul King
            jflinchbaugh John Flinchbaugh
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: