Error "Can't unambiguously select between fixed arity signatures" when trying to run v13.2
spustlik opened this issue ยท 13 comments
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]
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.
Ok, thank you, i will try it in short way:
- on Windows 10 machine, i build spigot using buildtool with -rev 1.13.2, java v1.8.0_121
Loading BuildTools version: git-BuildTools-5203e4b-75 (#75)...
...
Found version
{
"name": "1975",
"description": "Jenkins build 1975",
"refs": {
"BuildData": "f527a8ff0d2f2efafc292ac7648ae3a184245a74",
"Bukkit": "db06c80d7f7c8deeea1f6caf9cef549064897d05",
"CraftBukkit": "20fc5bea2c51de8d5239b68d83e878896b8ff505",
"Spigot": "26a8d99bf61328028e673b7c3e20729c0acbb078"
},
"toolsVersion": 75,
"javaVersions": [52, 55]
}
- started just created server in empty folder to create world & initiate other folders
- stopped server
- copyied scriptcraft.jar (v 3.3.0-2017-10-15) file length 167148 bytes into plugins
- started server again, exception thrown
[22:01:13 INFO]: [scriptcraft] Enabling scriptcraft v3.3.0-2017-10-15
...unzipping
...
[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;
}
The patch that I linked to previously, that @jwulf mentions above: ut7@2bdd337
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.
This approach does work.
The http
and https
methods in request.js
' and setInterval
need the same treatment.
@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.
Whenever the following error occurs:
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