Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

classes with methods / fields that reference unfound classes can't be used in mirror #20

Open
TPGamesNL opened this issue Jun 25, 2020 · 4 comments

Comments

@TPGamesNL
Copy link
Member

SkriptLang/Skript#3051

find out what Java standards are on this, because I probably won't support it if is deemed bad practice.

[13:55:42] [Server thread/WARN]: [Skript] Task #38 for Skript v2.5-alpha3 generated an exception
java.lang.NoClassDefFoundError: com/sucy/skill/SkillAPI
	at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:?]
	at java.lang.Class.privateGetDeclaredMethods(Class.java:3166) ~[?:?]
	at java.lang.Class.privateGetPublicMethods(Class.java:3191) ~[?:?]
	at java.lang.Class.getMethods(Class.java:1904) ~[?:?]
	at com.btk5h.skriptmirror.util.JavaUtil.methods(JavaUtil.java:53) ~[?:?]
	at com.btk5h.skriptmirror.skript.reflect.ExprJavaCall.createCallSite(ExprJavaCall.java:386) ~[?:?]
	at java.util.HashMap.computeIfAbsent(HashMap.java:1133) ~[?:?]
	at com.btk5h.skriptmirror.skript.reflect.ExprJavaCall.getCallSite(ExprJavaCall.java:346) ~[?:?]
	at com.btk5h.skriptmirror.skript.reflect.ExprJavaCall.findCompatibleMethod(ExprJavaCall.java:524) ~[?:?]
	at com.btk5h.skriptmirror.skript.reflect.ExprJavaCall.invoke(ExprJavaCall.java:435) ~[?:?]
	at com.btk5h.skriptmirror.skript.reflect.ExprJavaCall.getSingle(ExprJavaCall.java:137) ~[?:?]
	at com.btk5h.skriptmirror.skript.reflect.ExprJavaCall.getArray(ExprJavaCall.java:143) ~[?:?]
	at ch.njol.skript.effects.EffChange.execute(EffChange.java:278) ~[?:?]
	at ch.njol.skript.lang.Effect.run(Effect.java:52) ~[?:?]
	at ch.njol.skript.lang.TriggerItem.walk(TriggerItem.java:61) ~[?:?]
	at ch.njol.skript.lang.TriggerItem.walk(TriggerItem.java:89) ~[?:?]
	at ch.njol.skript.lang.Trigger.execute(Trigger.java:57) ~[?:?]
	at ch.njol.skript.events.EvtScript.register(EvtScript.java:61) ~[?:?]
	at ch.njol.skript.ScriptLoader$3.call(ScriptLoader.java:753) ~[?:?]
	at ch.njol.skript.ScriptLoader$3.call(ScriptLoader.java:1) ~[?:?]
	at ch.njol.skript.ScriptLoader.loadScript(ScriptLoader.java:772) ~[?:?]
	at ch.njol.skript.ScriptLoader.lambda$1(ScriptLoader.java:410) ~[?:?]
	at ch.njol.skript.ScriptLoader.loadScripts(ScriptLoader.java:429) ~[?:?]
	at ch.njol.skript.ScriptLoader.lambda$0(ScriptLoader.java:348) ~[?:?]
	at ch.njol.skript.ScriptLoader.loadScripts(ScriptLoader.java:381) ~[?:?]
	at ch.njol.skript.Skript$2.run(Skript.java:592) ~[?:?]
	at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftTask.run(CraftTask.java:64) ~[server.jar:git-Paper-33d42c8e]
	at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:423) ~[server.jar:git-Paper-33d42c8e]
	at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:852) ~[server.jar:git-Paper-33d42c8e]
	at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:423) ~[server.jar:git-Paper-33d42c8e]
	at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:786) ~[server.jar:git-Paper-33d42c8e]
	at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:678) ~[server.jar:git-Paper-33d42c8e]
	at java.lang.Thread.run(Thread.java:834) [?:?]
Caused by: java.lang.ClassNotFoundException: com.sucy.skill.SkillAPI
	at java.net.URLClassLoader.findClass(URLClassLoader.java:471) ~[?:?]
	at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:156) ~[server.jar:git-Paper-33d42c8e]
	at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:104) ~[server.jar:git-Paper-33d42c8e]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:588) ~[?:?]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[?:?]
	... 33 more

error is because mirror uses getMethods() instead of getMethod(String name)

@TPGamesNL
Copy link
Member Author

Yea I think I'm gonna try to fix it, even though it's probably bad practice

@TPGamesNL
Copy link
Member Author

TPGamesNL commented Jun 26, 2020

Look at MethodHandle, it might be helpful.
https://docs.oracle.com/javase/8/docs/api/java/lang/invoke/MethodType.html#genericMethodType-int-

https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#findVirtual(java.lang.Class,java.lang.String,java.lang.invoke.MethodType)

It might not be doable, only the name of the method is available at parse time, and methods can have the same names with different arguments.

@TPGamesNL
Copy link
Member Author

TPGamesNL commented Jul 1, 2020

Look at MethodHandle, it might be helpful.
https://docs.oracle.com/javase/8/docs/api/java/lang/invoke/MethodType.html#genericMethodType-int-

https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#findVirtual(java.lang.Class,java.lang.String,java.lang.invoke.MethodType)

It might not be doable, only the name of the method is available at parse time, and methods can have the same names with different arguments.

well it doesn't give errors, but I don't think it's a great solution, as mirror will need the parameter amount and each type, but it could be done anyway (with seperate syntax) for btk5h/skript-mirror#99 which then can be used if you come across this error.
EDIT: see https://tpgamesnl.gitbook.io/skript-reflect/basics/running-java-code#calling-overloaded-methods

@TPGamesNL
Copy link
Member Author

TPGamesNL commented Sep 16, 2022

Reopening, not because I'm going to fix it, but because I gotta rethrow the exception to include more context (which class' members are being looked up, etc)

https://pastebin.com/B1HCs3kt

@TPGamesNL TPGamesNL reopened this Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant