You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (Jira)" <ji...@apache.org> on 2021/01/29 13:13:01 UTC
[jira] [Created] (GROOVY-9920) Variable in script could not be
recognized properly
Daniel Sun created GROOVY-9920:
----------------------------------
Summary: Variable in script could not be recognized properly
Key: GROOVY-9920
URL: https://issues.apache.org/jira/browse/GROOVY-9920
Project: Groovy
Issue Type: Bug
Affects Versions: 3.0.7
Reporter: Daniel Sun
Got {{class list}}, but we expect {{[1, 2, 3]}}
{code:java}
import org.codehaus.groovy.runtime.InvokerHelper
def list = [1, 2, 3]
def strScript = 'list'
Class scriptClass = new GroovyClassLoader().parseClass(strScript, strScript)
Object result = InvokerHelper.createScript(scriptClass, new Binding(['list': list])).run()
System.out.println(result)
{code}
Workaround(add a space at the begining):
{code:java}
import org.codehaus.groovy.runtime.InvokerHelper
def list = [1, 2, 3]
def strScript = ' list'
Class scriptClass = new GroovyClassLoader().parseClass(strScript, strScript)
Object result = InvokerHelper.createScript(scriptClass, new Binding(['list': list])).run()
System.out.println(result)
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)