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

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.

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

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

"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"

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.

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/"];
];

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