You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2017/02/01 23:19:03 UTC

[jira] [Closed] (GROOVY-6947) NPE in compilation when assigning a value to 'this'

     [ https://issues.apache.org/jira/browse/GROOVY-6947?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-6947.
-----------------------------

> NPE in compilation when assigning a value to 'this'
> ---------------------------------------------------
>
>                 Key: GROOVY-6947
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6947
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.3.4
>            Reporter: Rodolfo Cruz
>            Assignee: Paul King
>            Priority: Minor
>             Fix For: 2.4.8
>
>         Attachments: groovyTest.groovy
>
>
> 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.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)