You can make _objects protected to overcome the MPE or use a local
variable, e.g.:

        def localVar = _objects
        1.times { localVar << it }

Cheers, Paul.


On Thu, May 28, 2020 at 7:42 AM o...@ocs.cz <o...@ocs.cz> wrote:

> 484 ocs /tmp> <q.groovy
> class q {
>   static main(av) {
>     new Foo().test()
>   }
> }
> class Foo extends Root { }
> class Root {
>     private _objects=[]
>     void test() {
>         println "this is OK"
>         _objects<<'hi'
>         println "this crashes"
>         1.times { _objects<<it }
>     }
> }
> 485 ocs /tmp> /usr/local/groovy-3.0.4/bin/groovy q
> this is OK
> this crashes
> Caught: groovy.lang.MissingPropertyException: No such property: _objects
> for class: Foo
> groovy.lang.MissingPropertyException: No such property: _objects for
> class: Foo
>         at Root$_test_closure1.doCall(q.groovy:13)
>         at Root.test(q.groovy:13)
>         at Root$test.call(Unknown Source)
>         at q.main(q.groovy:3)
> 486 ocs /tmp>
>
>

Reply via email to