The problem is that the Scripted object that is being casted to is being loaded by: sun.misc.Launcher$AppClassLoader@73d16e93, which is the system default class loader.
The ScriptEngine instance of Scripted was loaded in by: scala.reflect.internal.util.ScalaClassLoader$URLClassLoader@6397248c, scala’s internal class loader.
Making it impossible to get the ScriptEngine instance of Scripted, as far as I can tell.
Normally, this should not be a problem: each class loader should first
delegate to its parent class loader before it loads anything itself, and
any user-provided class loader should have the application class loader as
an ancestor (parent, parent of parent, etc)
I would check who the ancestors of the current class loader are, and
whether the two class loaders actually return different class objects when
asked to resolve the same class.