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