# Error: org.codehaus.groovy.reflection.CachedMethod can not access a member of class groovy.lang.Closure

**URL:** <https://discuss.elastic.co/t/error-org-codehaus-groovy-reflection-cachedmethod-can-not-access-a-member-of-class-groovy-lang-closure/60544>\
**Category:** Elasticsearch\
**Created:** [September 14, 2016, 8:14pm UTC](https://discuss.elastic.co/t/error-org-codehaus-groovy-reflection-cachedmethod-can-not-access-a-member-of-class-groovy-lang-closure/60544 "2016-09-14T20:14:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![srikanthjeeva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srikanthjeeva/32/11903_2.png) [@srikanthjeeva](https://discuss.elastic.co/u/srikanthjeeva)\
**Post date:** [September 14, 2016, 8:14pm UTC](https://discuss.elastic.co/t/error-org-codehaus-groovy-reflection-cachedmethod-can-not-access-a-member-of-class-groovy-lang-closure/60544/1 "2016-09-14T20:14:29Z")

</div>

I'm trying to execute this groovy script:

Working script in Groovy Console:

```
def m1 = [a:[1, 1, 1], b:[1, 1, 1], d:[1,1,1] ]
def m2 = [b:[1, 1, 1], c:[1, 1, 1] ]

def newMap = [m1,m2]*.keySet().flatten().unique().collectEntries {
  [(it): [m1,m2]*.get( it ).findAll().transpose()*.sum() ]
}

Result: [a:[1, 1, 1], b:[2, 2, 2], d:[1, 1, 1], c:[1, 1, 1]]

```

Running the same script in Elasticsearch:

```
{
  "script": "ctx._source.fn=[ctx._source.fn,fn]*.keySet().flatten().unique().collectEntries {[(it): [ctx._source.fn,fn]*.get( it ).findAll().transpose()*.sum() ]}", 
  "params": {
      "fn": {
        "test1": [2],  
        "test2": [2,2]  
      }
},
  "upsert": {
      "fn": {
        "test1": [2],  
        "test2": [2,2] 
      }
}
}     

```

The first time upsert works. But the second time the script fails with this error:

```
{
  "error": {
    "root_cause": [
      {
        "type": "remote_transport_exception",
        "reason": "[node_name][node_host_name/node_ip:9300][indices:data/write/update[s]]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "failed to execute script",
    "caused_by": {
      "type": "script_exception",
      "reason": "failed to run inline script [ctx._source.fn=[ctx._source.fn,fn]*.keySet().flatten().unique().collectEntries {[(it): [ctx._source.fn,fn]*.get( it ).findAll().transpose()*.sum() ]}] using lang [groovy]",
      "caused_by": {
        "type": "privileged_action_exception",
        "reason": null,
        "caused_by": {
          "type": "illegal_access_exception",
          "reason": "Class org.codehaus.groovy.reflection.CachedMethod can not access a member of class groovy.lang.Closure$1 with modifiers \"public\""
        }
      }
    }
  },
  "status": 400
}

```

I tried doing this: [https://github.com/ywelsch/elasticsearch/commit/87a13f88faadbfd27f032e24703bf8b96568a693](https://github.com/ywelsch/elasticsearch/commit/87a13f88faadbfd27f032e24703bf8b96568a693)

The java.security.policy file already has permission  
java.security.policy=/opt/pw/pronto/conf/java.security.policy

```
grant {
      // Allow everything for now
      permission java.security.AllPermission;
 };

```

How to proceed running this groovy script?

---

<div class="post-metadata">

**Author:** ![srikanthjeeva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srikanthjeeva/32/11903_2.png) [@srikanthjeeva](https://discuss.elastic.co/u/srikanthjeeva)\
**Post date:** [September 14, 2016, 10:23pm UTC](https://discuss.elastic.co/t/error-org-codehaus-groovy-reflection-cachedmethod-can-not-access-a-member-of-class-groovy-lang-closure/60544/2 "2016-09-14T22:23:27Z")

</div>

groovy findAll() method is causing this issue. Is there any alternative for findAll() ?

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [September 14, 2016, 10:24pm UTC](https://discuss.elastic.co/t/error-org-codehaus-groovy-reflection-cachedmethod-can-not-access-a-member-of-class-groovy-lang-closure/60544/3 "2016-09-14T22:24:51Z")

</div>

This is a known bug related to Groovy cached closure class inspection

> <https://github.com/elastic/elasticsearch/issues/14290>

---

<div class="post-metadata">

**Author:** ![srikanthjeeva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srikanthjeeva/32/11903_2.png) [@srikanthjeeva](https://discuss.elastic.co/u/srikanthjeeva)\
**Post date:** [September 14, 2016, 11:09pm UTC](https://discuss.elastic.co/t/error-org-codehaus-groovy-reflection-cachedmethod-can-not-access-a-member-of-class-groovy-lang-closure/60544/4 "2016-09-14T23:09:12Z")

</div>

Thank you!

I replaced the " findAll() " method to "minus(null)". and things works fine now.

So now my script looks like :

`"script": "ctx._source.fn=[ctx._source.fn,fn]*.keySet().flatten().unique().collectEntries { [(it): [ctx._source.fn,fn]*.get( it ).minus(null).transpose()*.sum()]}"`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:20pm UTC](https://discuss.elastic.co/t/error-org-codehaus-groovy-reflection-cachedmethod-can-not-access-a-member-of-class-groovy-lang-closure/60544/5 "2017-07-05T22:20:08Z")

</div>


