Duplicate :
|
|
Relates :
|
When implementing Java methods in Nashorn, optimistic types are not aware of the return type of the implemented method. This results in an incompatible method handle conversion from primitive to object return type: jjs> l = new java.util.List() { iterator: function() { return foo(); }}; jdk.nashorn.javaadapters.java_util_List@7e9131d5 jjs> l.iterator() java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle(ScriptFunction,Object)int to (ScriptFunction,Object)Iterator java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle(ScriptFunction,Object)int to (ScriptFunction,Object)Iterator at java.base/java.lang.invoke.MethodHandle.asTypeUncached(MethodHandle.java:858) at java.base/java.lang.invoke.MethodHandle.asType(MethodHandle.java:844) at jdk.dynalink/jdk.dynalink.TypeConverterFactory.asType(TypeConverterFactory.java:280) at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.asType(LinkerServicesImpl.java:131) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction.changeReturnType(CompiledFunction.java:734) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction.createInvoker(CompiledFunction.java:718) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction.access$200(CompiledFunction.java:62) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction$2.get(CompiledFunction.java:680) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction$2.get(CompiledFunction.java:677) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction.getValidOptimisticInvocation(CompiledFunction.java:623) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction.createFunctionInvocation(CompiledFunction.java:677) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.findCallMethod(ScriptFunction.java:949) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptObject.lookup(ScriptObject.java:1874) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:104) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:96) at jdk.dynalink/jdk.dynalink.linker.support.CompositeTypeBasedGuardingDynamicLinker.getGuardedInvocation(CompositeTypeBasedGuardingDynamicLinker.java:184) at jdk.dynalink/jdk.dynalink.linker.support.CompositeGuardingDynamicLinker.getGuardedInvocation(CompositeGuardingDynamicLinker.java:132) at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.lambda$getGuardedInvocation$0(LinkerServicesImpl.java:160) at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.getWithLookupInternal(LinkerServicesImpl.java:191) at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.getGuardedInvocation(LinkerServicesImpl.java:158) at jdk.dynalink/jdk.dynalink.DynamicLinker.relink(DynamicLinker.java:265) at jdk.nashorn.javaadapters.java_util_List.iterator(Unknown Source) at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$3$\^shell\_/1604353554.:program(<shell>:1) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:655) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:517) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.Context.eval(Context.java:861) at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.Context.eval(Context.java:796) at jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.readEvalPrint(Main.java:218) at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.run(Shell.java:175) at jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:104) at jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:80)