# Painless Script runtime error: dynamic method \[java.util.ArrayList, entrySet/0\] not found

**URL:** <https://discuss.elastic.co/t/painless-script-runtime-error-dynamic-method-java-util-arraylist-entryset-0-not-found/340775>\
**Category:** Elasticsearch\
**Tags:** painless, runtime-fields\
**Created:** [August 14, 2023, 4:47pm UTC](https://discuss.elastic.co/t/painless-script-runtime-error-dynamic-method-java-util-arraylist-entryset-0-not-found/340775 "2023-08-14T16:47:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anni](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Anni](https://discuss.elastic.co/u/Anni)\
**Post date:** [August 14, 2023, 4:47pm UTC](https://discuss.elastic.co/t/painless-script-runtime-error-dynamic-method-java-util-arraylist-entryset-0-not-found/340775/1 "2023-08-14T16:47:41Z")

</div>

I am getting _"dynamic method [java.util.ArrayList, entrySet/0] not found"_ error while running the painless script in watchers.

Here is the simplified version of the code. I tried to recreate the issue in dev tools but I could not. I am getting the results as you can see in the screenshot but it is failing in PROD for some reason.

**processes** Hashmap is exactly the same that I am using in PROD script.

```auto
def processes = [
      "Server1": ["/tomcat_prd_03/" : "tomcat_prd_03 (sg-prime1)", "/tomcat_prd_04/" : "tomcat_prd_04 (Prime)"],
      "Server2": ["/tomcat_prd_03/" : "tomcat_prd_03 (sg-prime1)", "/tomcat_prd_04/" : "tomcat_prd_04 (Alpha)"],
      "Server3": ["/tomcat_prd_03/" : "tomcat_prd_03 (sg-prime1)", "/tomcat_prd_04/" : "tomcat_prd_04 (Prime2)"],
      "Server4": ["/tomcat_prd_03/" : "tomcat_prd_03 (sg-prime1)", "/tomcat_prd_04/" : "tomcat_prd_04 (Prime1)"]];

def process_args = processes.get("Server3");
def result;

if (process_args != null) {
     for (entry in process_args.entrySet()) { --> Complaining here as you can see in the logs.
        def process_arg = entry.getKey();
        def serviceName = entry.getValue();
        result = "Key => " + process_arg + " value =>" + serviceName; // Returns the Last value
       // Rest of the code that is running in for loop
     }

}
result;

```

**Dev tools output**

I would except the same results in PROD as well but instead I get this error "dynamic method [java.util.ArrayList, entrySet/0] not found.

![image](https://us1.discourse-cdn.com/elastic/original/3X/7/0/700d2a26c5602a6e17d1915bfa175b5b2f0d0c94.png)

**Below is the actual error that I am getting in PROD when running painless script in watchers.**

```auto
"exception": {
    "type": "script_exception",
    "reason": "runtime error",
    "script_stack": [
      "for (entry in process_args.entrySet()) {\n def ",
      " ^---- HERE"
    ],
    "script": " ...",
    "lang": "painless",
    "position": {
      "offset": 6015,
      "start": 5989,
      "end": 6045
    },
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "dynamic method [java.util.ArrayList, entrySet/0] not found"

```

---

<div class="post-metadata">

**Author:** ![Anni](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Anni](https://discuss.elastic.co/u/Anni)\
**Post date:** [August 14, 2023, 7:26pm UTC](https://discuss.elastic.co/t/painless-script-runtime-error-dynamic-method-java-util-arraylist-entryset-0-not-found/340775/2 "2023-08-14T19:26:45Z")

</div>

I have found the issue. Adding the solution here just in case someone else come across the similar  
issue.

In my case it was a data issues. I had a long list of hashmaps inside an array.  
Check out the "Server5" record. **When you do processes.get(hostName), it will return an array and there is no entryset() method for array.**

```auto
def processes = [
      "Server1": ["/tomcat_prd_03/" : "tomcat_prd_03 (sg-prime1)", "/tomcat_prd_04/" : "tomcat_prd_04 (Prime)"],
      "Server2": ["/tomcat_prd_03/" : "tomcat_prd_03 (sg-prime1)", "/tomcat_prd_04/" : "tomcat_prd_04 (Alpha)"],
      "Server3": ["/tomcat_prd_03/" : "tomcat_prd_03 (sg-prime1)", "/tomcat_prd_04/" : "tomcat_prd_04 (Prime2)"],
      "Server4": ["/tomcat_prd_03/" : "tomcat_prd_03 (sg-prime1)", "/tomcat_prd_04/" : "tomcat_prd_04 (Prime1)"],
      "Server5": ["/tomcat_prd_03/", "/tomcat_prd_04/"];
];

```

---

<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:** [September 11, 2023, 7:26pm UTC](https://discuss.elastic.co/t/painless-script-runtime-error-dynamic-method-java-util-arraylist-entryset-0-not-found/340775/3 "2023-09-11T19:26:56Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
