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

Can't update static variable from closure in static method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-3
    • 1.0-beta-3
    • None
    • None

    Description

      I added another test to the bug class below that attempts to update a static variable from with a closure in a static method. The result of the new test is this Error:

      java.lang.NoSuchFieldError: owner
      at UseStaticInClosureBug$2.doCall(C:\dev\cvsviews\groovy\groovy-core\target\test-classes\groovy\bugs\UseStaticInClosureBug.groovy)

      class UseStaticInClosureBug extends GroovyTestCase {

      static stuff = [:]

      void testBug() {
      [1,2,3].each

      { stuff[it] = "dog" }

      assert stuff.size() == 3
      assert stuff[2] == "dog"
      }

      void testBug2() { doStatic() }

      static doStatic() {
      [1,2,3].each { stuff[it] = "dog" }

      assert stuff.size() == 3
      assert stuff[2] == "dog"
      }
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            rodcope Rod Cope
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: