javax.script.ScriptException: Repl history mismatch at line: 1

Hi, I am trying to run scripts with Kotlin, seems that when I try to eval a org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.CompiledKotlinScript it gives a:

javax.script.ScriptException: Repl history mismatch at line: 1
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.asJsr223EvalResult(KotlinJsr223JvmScriptEngineBase.kt:107)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.eval(KotlinJsr223JvmScriptEngineBase.kt:83)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase$CompiledKotlinScript.eval(KotlinJsr223JvmScriptEngineBase.kt:112)
at javax.script.CompiledScript.eval(CompiledScript.java:106)

Tried to see the decompiled class and go through the exception but didn’t find the reason because it was kinda obfuscated. There is also another error that I can’t track and don’t know how it happens and what produces it.

Exception in thread “main” javax.script.ScriptException: java.lang.NoSuchMethodException: Line_5.(javax.script.Bindings)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.asJsr223EvalResult(KotlinJsr223JvmScriptEngineBase.kt:92)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.eval(KotlinJsr223JvmScriptEngineBase.kt:83)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase$CompiledKotlinScript.eval(KotlinJsr223JvmScriptEngineBase.kt:112)

If needed I can try to create a project so you can reproduce the problem.

For someone experiencing the same issue there is two ways that I found to solve this:

Never use the same ScriptEngine two times.
Use BasicJvmScriptingHost instead of ScriptEngine.

Hope I helped out.