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

NPE in compilation when assigning a value to 'this'

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.3.4
    • 2.4.8
    • Compiler
    • None

    Description

      We're using Groovy to allow users to write some scripts inside a product and one of them tried to assign a value to the variable "this", leading to the following exception (test case is attached):

      BUG! exception in phase 'semantic analysis' in source unit 'groovyTest.groovy' null
      at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:927)
      at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:585)
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:534)
      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$0.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.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: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:278)
      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.classgen.VariableScopeVisitor.checkForFinal(VariableScopeVisitor.java:392)
      at org.codehaus.groovy.classgen.VariableScopeVisitor.checkFinalFieldAccess(VariableScopeVisitor.java:385)
      at org.codehaus.groovy.classgen.VariableScopeVisitor.visitBinaryExpression(VariableScopeVisitor.java:369)
      at org.codehaus.groovy.ast.expr.BinaryExpression.visit(BinaryExpression.java:49)
      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.classgen.VariableScopeVisitor.visitBlockStatement(VariableScopeVisitor.java:312)
      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.classgen.VariableScopeVisitor.visitConstructorOrMethod(VariableScopeVisitor.java:509)
      at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:123)
      at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1063)
      at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
      at org.codehaus.groovy.classgen.VariableScopeVisitor.visitClass(VariableScopeVisitor.java:477)
      at org.codehaus.groovy.control.CompilationUnit$11.call(CompilationUnit.java:640)
      at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:923)
      ... 23 more

      I know this is an issue that won't happen very often as this is invalid code (that's the reason of the lower priority), but it would nice if you could have a look into this and handle the exception, reporting it as a compilation issue.

      Attachments

        1. groovyTest.groovy
          0.1 kB
          Rodolfo Cruz

        Issue Links

          Activity

            People

              paulk Paul King
              rcruzjo Rodolfo Cruz
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: