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

Not being able to refer to global variables via scripted methods

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Information Provided
    • 2.4.11
    • None
    • GroovyScriptEngine
    • None
    • Probably not relevant, but problem at least confirmed on Mac OS X

    Description

      We wish to switch from BeanShell to Groovy as script language (JSR-223) in our desktop software jAlbum. jAlbum injects a set of global variables into the scriptlets via the Bindings object of the JSR-223 API. These variables are directly accessible in simple scripts, but contrary to scripting in BeanShell, these variables are not available to methods declared within scripted classes.

      Here's what works (assuming that "foo" is passed to the GroovyScriptEngine via the Bindings object):

      println(foo) // foo being made available to the magically created Script class' run method

      Here's what won't work (foo again being passed to the GroovyScriptEngine via the Bindings object):

      class Test {
      void bar()

      { println(foo); // Reference to missing variable }

      }

      Test t = new Test()
      t.bar() // Fails due to missing variable

      Attachments

        Activity

          People

            Unassigned Unassigned
            davidekholm David Ekholm
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: