ScriptEngine#get doesn't work like other script engines

I’m trying to add support for Kotlin to the Apache NiFi scripting bundle and ran into some weird behavior in Kotlin’s JSR223 engine. A lot of our scriptable processors and services assume that you can fetch objects from the processed script and invoke them using the java scripting components as shown in the screenshot below.

When I do that from Kotlin, it’s not able to fetch a script-level variable called processor from the script. Is this bug or expected behavior from the Kotlin JS223 implementation? I’m using Kotlin 1.7.20 as the dependency in this NiFi bundle so it should be the absolute latest Kotlin release.

I don’t have any ideas yet but wanted to ask: is the code published anywhere yet? For those of use who use NiFi, it’d be nice to try running it and possibly contribute

The code shown there is part of the standard NiFi distribution. You can find the full class here.

The problem isn’t with NiFi per se, but rather the JSR223 implementation for Kotlin not behaving in a way that is expected and consistent with Groovy, JavaScript, etc.