You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error "Can't unambiguously select between fixed arity signatures" when trying to run v13.2 #396
When i tried to compile and run scriptcraft with v 13.2, it throw an error (see later)
I tried to do some more investigation but without success - it is from lib/scriptcraft.js which is requiring js-patch and unit-testing setTimeout method.
Any possibility to fix it ?
Thank you...
[21:00:50 INFO]: [scriptcraft] Enabling scriptcraft v3.3.0-2017-10-15
[21:00:52 ERROR]: [scriptcraft] Error evaluating scriptcraft\lib\scriptcraft.js: java.lang.NoSuchMethodException: Can't unambiguously select between fixed arity signatures [(org.bukkit.plugin.Plugin, java.util.function.Consumer, long), (org.bukkit.plugin.Plugin, java.lang.Runnable, long)] of the method org.bukkit.craftbukkit.v1_13_R2.scheduler.CraftScheduler.runTaskLater for argument types [org.scriptcraftjs.bukkit.ScriptCraftPlugin, jdk.nashorn.internal.runtime.ScriptFunction, java.lang.Double]
[21:00:52 WARN]: java.lang.NoSuchMethodException: Can't unambiguously select between fixed arity signatures [(org.bukkit.plugin.Plugin, java.util.function.Consumer, long), (org.bukkit.plugin.Plugin, java.lang.Runnable, long)] of the method org.bukkit.craftbukkit.v1_13_R2.scheduler.CraftScheduler.runTaskLater for argument types [org.scriptcraftjs.bukkit.ScriptCraftPlugin, jdk.nashorn.internal.runtime.ScriptFunction, java.lang.Double]
[21:00:52 WARN]: at jdk.internal.dynalink.beans.OverloadedMethod.throwAmbiguousMethod(OverloadedMethod.java:225)
[21:00:52 WARN]: at jdk.nashorn.internal.scripts.Script$Recompilation$32$158AI$\^eval\_.L:1#bukkitSetTimeout(<eval>:5)
[21:00:52 WARN]: at jdk.nashorn.internal.scripts.Script$Recompilation$31$1905A$\^eval\_.L:1#exports#unitTest(<eval>:57)
[21:00:52 WARN]: at jdk.nashorn.internal.scripts.Script$Recompilation$5$16346AAA$\^eval\_.__onEnable(<eval>:754)
[21:00:52 WARN]: at jdk.nashorn.internal.scripts.Script$Recompilation$2$1583AAA$\^eval\_.L:5#__scboot(<eval>:90)
[21:00:52 WARN]: at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:643)
[21:00:52 WARN]: at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
[21:00:52 WARN]: at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
[21:00:52 WARN]: at jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:199)
[21:00:52 WARN]: at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:386)
[21:00:52 WARN]: at jdk.nashorn.api.scripting.NashornScriptEngine.invokeFunction(NashornScriptEngine.java:190)
[21:00:52 WARN]: at org.scriptcraftjs.bukkit.ScriptCraftPlugin.onEnable(ScriptCraftPlugin.java:38)
[21:00:52 WARN]: at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:254)
[21:00:52 WARN]: at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:339)
[21:00:52 WARN]: at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403)
[21:00:52 WARN]: at org.bukkit.craftbukkit.v1_13_R2.CraftServer.enablePlugin(CraftServer.java:434)
[21:00:52 WARN]: at org.bukkit.craftbukkit.v1_13_R2.CraftServer.enablePlugins(CraftServer.java:348)
[21:00:52 WARN]: at net.minecraft.server.v1_13_R2.MinecraftServer.l(MinecraftServer.java:584)
[21:00:52 WARN]: at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:546)
[21:00:52 WARN]: at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:424)
[21:00:52 WARN]: at net.minecraft.server.v1_13_R2.DedicatedServer.init(DedicatedServer.java:294)
[21:00:52 WARN]: at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:702)
[21:00:52 WARN]: at java.lang.Thread.run(Unknown Source)
[21:00:52 ERROR]: [scriptcraft] Can't unambiguously select between fixed arity signatures [(org.bukkit.plugin.Plugin, java.util.function.Consumer, long), (org.bukkit.plugin.Plugin, java.lang.Runnable, long)] of the method org.bukkit.craftbukkit.v1_13_R2.scheduler.CraftScheduler.runTaskLater for argument types [org.scriptcraftjs.bukkit.ScriptCraftPlugin, jdk.nashorn.internal.runtime.ScriptFunction, java.lang.Double]
[22:01:25 ERROR]: [scriptcraft] Error evaluating scriptcraft\lib\scriptcraft.js: java.lang.NoSuchMethodException: Can't unambiguously select between fixed arity signatures [(org.bukkit.plugin.Plugin, java.lang.Runnable, long), (org.bukkit.plugin.Plugin, java.util.function.Consumer, long)] of the method org.bukkit.craftbukkit.v1_13_R2.scheduler.CraftScheduler.runTaskLater for argument types [org.scriptcraftjs.bukkit.ScriptCraftPlugin, jdk.nashorn.internal.runtime.ScriptFunction, java.lang.Double]
[22:01:25 WARN]: java.lang.NoSuchMethodException: Can't unambiguously select between fixed arity signatures [(org.bukkit.plugin.Plugin, java.lang.Runnable, long), (org.bukkit.plugin.Plugin, java.util.function.Consumer, long)] of the method org.bukkit.craftbukkit.v1_13_R2.scheduler.CraftScheduler.runTaskLater for argument types [org.scriptcraftjs.bukkit.ScriptCraftPlugin, jdk.nashorn.internal.runtime.ScriptFunction, java.lang.Double]
[22:01:25 WARN]: at jdk.internal.dynalink.beans.OverloadedMethod.throwAmbiguousMethod(OverloadedMethod.java:225)
[22:01:25 WARN]: at jdk.nashorn.internal.scripts.Script$Recompilation$32$158AI$\^eval\_.L:1#bukkitSetTimeout(<eval>:5)
[22:01:25 WARN]: at jdk.nashorn.internal.scripts.Script$Recompilation$31$1905A$\^eval\_.L:1#exports#unitTest(<eval>:57)
[22:01:25 WARN]: at jdk.nashorn.internal.scripts.Script$Recompilation$5$16346AAA$\^eval\_.__onEnable(<eval>:754)
[22:01:25 WARN]: at jdk.nashorn.internal.scripts.Script$Recompilation$2$1583AAA$\^eval\_.L:5#__scboot(<eval>:90)
[22:01:25 WARN]: at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:643)
[22:01:25 WARN]: at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
[22:01:25 WARN]: at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
[22:01:25 WARN]: at jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:199)
[22:01:25 WARN]: at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:386)
[22:01:25 WARN]: at jdk.nashorn.api.scripting.NashornScriptEngine.invokeFunction(NashornScriptEngine.java:190)
[22:01:25 WARN]: at org.scriptcraftjs.bukkit.ScriptCraftPlugin.onEnable(ScriptCraftPlugin.java:38)
[22:01:25 WARN]: at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:254)
[22:01:25 WARN]: at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:339)
[22:01:25 WARN]: at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403)
[22:01:25 WARN]: at org.bukkit.craftbukkit.v1_13_R2.CraftServer.enablePlugin(CraftServer.java:434)
[22:01:25 WARN]: at org.bukkit.craftbukkit.v1_13_R2.CraftServer.enablePlugins(CraftServer.java:348)
[22:01:25 WARN]: at net.minecraft.server.v1_13_R2.MinecraftServer.l(MinecraftServer.java:584)
[22:01:25 WARN]: at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:546)
[22:01:25 WARN]: at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:424)
[22:01:25 WARN]: at net.minecraft.server.v1_13_R2.DedicatedServer.init(DedicatedServer.java:294)
[22:01:25 WARN]: at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:702)
[22:01:25 WARN]: at java.lang.Thread.run(Unknown Source)
It seems that it cannot map java function to javascript in file lib/js-patch.js line 57:
$.setTimeout(function(){
console.log('js-patch setTimeout() test complete');
},100);
second thing I found comparing old and new javascripts is that modules/underscore.js is GZIPed on the disc (file size only 17KB), but maybe it can be stil loaded...
I can send some logs, If you wish,
thank you again.
There are two Java implementations for server.scheduler.runTaskLater, with different signatures - one that takes a java.lang.Runnable and another that takes a java.util.function.Consumer. The runtime selects the correct one based on the type of the arguments passed into the call.
The Javascript callback function is being passed to Java as a type jdk.nashorn.internal.runtime.ScriptFunction and needs to be cast into either a java.lang.Runnable or a java.util.function.Consumer. The problem is that Java can't do that cast automatically - either because neither can be done, or because both could be done.
The patch @triyuga linked to explicitly specifies which implementation to use. That may work if the JVM can cast jdk.nashorn.internal.runtime.ScriptFunction -> java.lang.Runnable or -> java.util.function.Consumer.
Otherwise, I would try next explicitly constructing one of the accepted types from the callback. Maybe like this in src/js/main/lib/task-bukkit.js (from "Extending Java classes" here):
function bukkitSetTimeout( callback, delayInMillis ){
var delay = Math.ceil( delayInMillis / 50 );
var Run = Java.type("java.lang.Runnable");
var MyRun = Java.extend(Run, {
run: callback
});
var task = server.scheduler.runTaskLater( __plugin, new MyRun(), delay );
return task;
}
@jwulf Thanks for the PR.
You're right - there are a couple of other places where I need to fix this (setInterval also needs to be fixed). I'll post something shortly.
Can't unambiguously select between fixed arity signatures
It's because of overloaded functions (specifically functions with the same number of params in their signature but with different param types). Rhino & Nashorn both let you explicitly specify which overload (signature) you want to use by specifying the function/param combo as a string property of the object.
See f760157#diff-d09711779c520b5ceb965bc1a5ac5b4eL17
Activity
jwulf commentedon Dec 3, 2018
I'd say the matching signature is the one that wants a Long.
I can debug this if you give me the steps to reproduce it on my machine.
spustlik commentedon Dec 5, 2018
Ok, thank you, i will try it in short way:
It seems that it cannot map java function to javascript in file lib/js-patch.js line 57:
second thing I found comparing old and new javascripts is that modules/underscore.js is GZIPed on the disc (file size only 17KB), but maybe it can be stil loaded...
I can send some logs, If you wish,
thank you again.
chernish2 commentedon Dec 13, 2018
Have exactly the same error, how to fix?
AbelYANG2022 commentedon Dec 14, 2018
same error here.
bitcog commentedon Dec 27, 2018
I'm stuck with this one too - any fixes or work-arounds?
geekyinsights commentedon Jan 14, 2019
Same error.
jwulf commentedon Jan 17, 2019
oracle/graaljs#37
jwulf commentedon Jan 17, 2019
There are two Java implementations for
server.scheduler.runTaskLater, with different signatures - one that takes ajava.lang.Runnableand another that takes ajava.util.function.Consumer. The runtime selects the correct one based on the type of the arguments passed into the call.The Javascript callback function is being passed to Java as a type
jdk.nashorn.internal.runtime.ScriptFunctionand needs to be cast into either ajava.lang.Runnableor ajava.util.function.Consumer. The problem is that Java can't do that cast automatically - either because neither can be done, or because both could be done.The patch @triyuga linked to explicitly specifies which implementation to use. That may work if the JVM can cast
jdk.nashorn.internal.runtime.ScriptFunction->java.lang.Runnableor ->java.util.function.Consumer.Otherwise, I would try next explicitly constructing one of the accepted types from the callback. Maybe like this in
src/js/main/lib/task-bukkit.js(from "Extending Java classes" here):tim-marwick commentedon Jan 17, 2019
The patch that I linked to previously, that @jwulf mentions above: ut7@2bdd337
jwulf commentedon Jan 17, 2019
I've patched this branch in my fork: https://github.com/jwulf/ScriptCraft/tree/setTimeout-fix
I don't have 1.13 set up, but if someone wants to test it, please be my guest.
jwulf commentedon Jan 19, 2019
This approach does work.
The
httpandhttpsmethods inrequest.js' andsetIntervalneed the same treatment.walterhiggins commentedon Jan 20, 2019
@jwulf Thanks for the PR.
You're right - there are a couple of other places where I need to fix this (setInterval also needs to be fixed). I'll post something shortly.
Fixes bug #396
walterhiggins commentedon Jan 20, 2019
Whenever the following error occurs:
It's because of overloaded functions (specifically functions with the same number of params in their signature but with different param types). Rhino & Nashorn both let you explicitly specify which overload (signature) you want to use by specifying the function/param combo as a string property of the object.
See f760157#diff-d09711779c520b5ceb965bc1a5ac5b4eL17