Class GraalJsValueUtil

java.lang.Object
org.camunda.commons.utils.GraalJsValueUtil

public final class GraalJsValueUtil extends Object

Deep-copies a GraalJS-produced Map/List into plain LinkedHashMap/ArrayList instances - see issue #3236.

GraalJS's JSR-223 wrapper never materializes a returned JS object/array into a plain Java collection: it hands back a lazy com.oracle.truffle.polyglot.PolyglotMap/ PolyglotArray view that calls back into the org.graalvm.polyglot.Context it came from on every real access (e.g. entrySet()). Callers that dispose that Context's engine right after the script returns - as every GraalJS evaluation does since issue #3185 - leave any such value unusable the moment anything touches it, throwing IllegalStateException: The Context is already closed.

Detection is purely by the value's own runtime class name, never by importing any org.graalvm/com.oracle.truffle type: those classes are only ever an optional, reflectively-loaded runtime dependency of GraalJS's embedders, never a compile-time dependency here. This also means an ordinary, non-GraalJS Map/List (e.g. one a Java delegate or a different script engine produced) is left completely untouched - only values actually backed by GraalJS's Truffle/Polyglot implementation are ever copied.

  • Method Details

    • materialize

      public static Object materialize(Object value)
      Parameters:
      value - the value to materialize, as returned by a GraalJS script/expression evaluation
      Returns:
      value unchanged if it is not itself backed by GraalJS's Truffle/Polyglot implementation - an ordinary Java Map/List (or any other object) is never inspected, let alone copied; otherwise a deep copy in which value and every Polyglot-backed Map/List reachable from it has been replaced by a plain LinkedHashMap/ArrayList - safe to use after the Context that produced value has been closed