Upgrade to 7.23 Causes Javascript Failure

We make extensive use of javascript in our bpmn models. Upon upgrading from Camunda 7.22.0 to 7.23.0, a service task with existing javascript now fails. We are using the docker version of the Tomcat distribution. In our bpm-platform.xml file we have been using the compatibility mode with the previous javascript engine with:
<property name="enableScriptEngineNashornCompatibility">true</property>

The error from the Catalina log that we are now getting is:

org.camunda.bpm.engine.ScriptEvaluationException: Unable to evaluate script while executing activity 'ce609242_0f8d_4985_8594_740e9a5347b6_assignPermissions' in the process definition with id 'd52c4928-358f-11f0-9a75-c62da50a19d9':org.graalvm.polyglot.PolyglotException: TypeError: deduped.findIndex is not a function

The javascript in question is in a Rest Connector service task, in the payload specification for the Input Parameters. The portion of the script that causes the error is:

 const dedupedAssignees = modifiedAssignees.reduce((deduped, current) => {
      const existingIndex = deduped.findIndex(item => item.assignee === current.assignee);
   ...
return deduped;
    }, []);

The variable deduped is clearly an array so the function findIndex should not be undefined.

We have found that if we remove the Nashorn compatibility setting from the bpm-platform.xml file that the problem is gone. However, this is not a viable option because we have extensive javascripting that relies on this setting.

So for us, this upgrade to v7.23.0 is a breaking change. Do you have any idea what the cause of the error could be and how this can be resolved?

@Stephen_Bucholtz ,

1. Force conversion to a JS array (Array.from())

Before calling .findIndex(), make sure you’re working with a real JS array:

const dedupedAssignees = modifiedAssignees.reduce((deduped, current) => {
  const jsArray = Array.from(deduped); // Force conversion
  const existingIndex = jsArray.findIndex(item => item.assignee === current.assignee);
  if (existingIndex === -1) {
    deduped.push(current);
  }
  return deduped;
}, []);

This ensures that .findIndex() is available regardless of how deduped is internally represented.

2. Use .some() and .map() if you can’t convert

If Array.from() doesn’t work reliably across your scripts, use this workaround:

let dedupedAssignees = [];

for (let i = 0; i < modifiedAssignees.length; i++) {
  const current = modifiedAssignees[i];
  const exists = dedupedAssignees.some(item => item.assignee === current.assignee);
  if (!exists) {
    dedupedAssignees.push(current);
  }
}

3. Avoid .findIndex() in Nashorn mode — stick to ES5-style JS

GraalJS in Nashorn compatibility mode struggles with ES6+ methods like find, findIndex, etc., especially when underlying objects are Java collections. Prefer basic for loops and some() as those are more broadly supported.

Thank you for the various suggestions.

We ended up adding the following to setenv.sh to force a specific ecmascript version which supports findIndex():

export JAVA_OPTS="$JAVA_OPTS -Dpolyglot.js.ecmascript-version=2020"