FabricMC / fabric-language-scala

Fabric language module for Scala.
Apache License 2.0
43 stars 17 forks source link

Issue about jna #17

Open plusls opened 3 years ago

plusls commented 3 years ago

I found that fabric-language-scala@1.1.0+scala.2.13.6 in curseforge contains com.sun.jna, after I install fabric-language-scala, it will cause jna register fail, print

[16:54:32] [Render thread/INFO]: [STDERR]: java.lang.ExceptionInInitializerError
[16:54:32] [Render thread/INFO]: [STDERR]:  at java.base/java.lang.Class.forName0(Native Method)
[16:54:32] [Render thread/INFO]: [STDERR]:  at java.base/java.lang.Class.forName(Class.java:375)
[16:54:32] [Render thread/INFO]: [STDERR]:  at com.ddwhm.jesen.imblocker.ImBlocker.<clinit>(ImBlocker.java:29)
[16:54:32] [Render thread/INFO]: [STDERR]:  at java.base/java.lang.Class.forName0(Native Method)
[16:54:32] [Render thread/INFO]: [STDERR]:  at java.base/java.lang.Class.forName(Class.java:466)
[16:54:32] [Render thread/INFO]: [STDERR]:  at net.fabricmc.loader.util.DefaultLanguageAdapter.create(DefaultLanguageAdapter.java:50)
[16:54:32] [Render thread/INFO]: [STDERR]:  at net.fabricmc.loader.EntrypointStorage$NewEntry.lambda$getOrCreate$0(EntrypointStorage.java:106)
[16:54:32] [Render thread/INFO]: [STDERR]:  at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1224)
[16:54:32] [Render thread/INFO]: [STDERR]:  at net.fabricmc.loader.EntrypointStorage$NewEntry.getOrCreate(EntrypointStorage.java:104)
[16:54:32] [Render thread/INFO]: [STDERR]:  at net.fabricmc.loader.EntrypointStorage.lambda$getEntrypointContainers$1(EntrypointStorage.java:191)
[16:54:32] [Render thread/INFO]: [STDERR]:  at net.fabricmc.loader.entrypoint.EntrypointContainerImpl.getEntrypoint(EntrypointContainerImpl.java:37)
[16:54:32] [Render thread/INFO]: [STDERR]:  at net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointUtils.invoke0(EntrypointUtils.java:47)
[16:54:32] [Render thread/INFO]: [STDERR]:  at net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointUtils.invoke(EntrypointUtils.java:33)
[16:54:32] [Render thread/INFO]: [STDERR]:  at net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointClient.start(EntrypointClient.java:34)
[16:54:32] [Render thread/INFO]: [STDERR]:  at net.minecraft.class_310.redirect$bbi000$catchFabricInit(class_310.java:10064)
[16:54:32] [Render thread/INFO]: [STDERR]:  at net.minecraft.class_310.<init>(class_310.java:457)
[16:54:32] [Render thread/INFO]: [STDERR]:  at net.minecraft.client.main.Main.main(Main.java:179)
[16:54:32] [Render thread/INFO]: [STDERR]:  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[16:54:32] [Render thread/INFO]: [STDERR]:  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
[16:54:32] [Render thread/INFO]: [STDERR]:  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[16:54:32] [Render thread/INFO]: [STDERR]:  at java.base/java.lang.reflect.Method.invoke(Method.java:567)
[16:54:32] [Render thread/INFO]: [STDERR]:  at net.fabricmc.loader.game.MinecraftGameProvider.launch(MinecraftGameProvider.java:234)
[16:54:32] [Render thread/INFO]: [STDERR]:  at net.fabricmc.loader.launch.knot.Knot.launch(Knot.java:153)
[16:54:32] [Render thread/INFO]: [STDERR]:  at net.fabricmc.loader.launch.knot.KnotClient.main(KnotClient.java:28)
[16:54:32] [Render thread/INFO]: [STDERR]: Caused by: java.lang.IllegalArgumentException: class com.sun.jna.platform.win32.WinNT$HANDLE is not a supported return type (in method ImmAssociateContext in class com.ddwhm.jesen.imblocker.immanager.windows.WindowsImManager)
[16:54:32] [Render thread/INFO]: [STDERR]:  at com.sun.jna.Native.register(Native.java:1765)
[16:54:32] [Render thread/INFO]: [STDERR]:  at com.sun.jna.Native.register(Native.java:1723)
[16:54:32] [Render thread/INFO]: [STDERR]:  at com.sun.jna.Native.register(Native.java:1443)
[16:54:32] [Render thread/INFO]: [STDERR]:  at com.ddwhm.jesen.imblocker.immanager.windows.WindowsImManager.<clinit>(WindowsImManager.java:30)
[16:54:32] [Render thread/INFO]: [STDERR]:  ... 24 more

I read the source code in jna, and found that Native.getConversion return -1.

https://github.com/java-native-access/jna/blob/7ae36913c7094f14fc841555c8dd36ffdb67a3ee/src/com/sun/jna/Native.java#L1731

And I write the test code:

        ImBlocker.LOGGER.info("check WinNT.HANDLE {}", PointerType.class.isAssignableFrom(WinNT.HANDLE.class));
        ImBlocker.LOGGER.info("check WinDef.HWND {}", PointerType.class.isAssignableFrom(WinDef.HWND.class));
        ImBlocker.LOGGER.info("check WinDef.HWND {}", WinNT.HANDLE.class.isAssignableFrom(WinDef.HWND.class));

Before install fabric-language-scala:

[16:53:05] [Render thread/INFO]: check WinNT.HANDLE true
[16:53:05] [Render thread/INFO]: check WinDef.HWND true
[16:53:05] [Render thread/INFO]: check WinDef.HWND true

After install fabric-language-scala:

[16:54:31] [Render thread/INFO]: check WinNT.HANDLE false
[16:54:31] [Render thread/INFO]: check WinDef.HWND false
[16:54:31] [Render thread/INFO]: check WinDef.HWND true
magneticflux- commented 3 years ago

This is a serious problem that affects mod that uses JNA. Could we get backports of the library to fix all latest major versions of Minecraft?

Honestly, just a copy/paste of the Kotlin project seems to be in order. That repo has received significantly more love than this one, and the improvements could be easily transferred.

modmuss50 commented 3 years ago

Just to confirm this was caused by the latest update to scala? If so I can remove the broken build.

modmuss50 commented 3 years ago

The kotlin project is also a right pain to maintain, if it ever requires more work than just changing version numbers I will most likely rewrite to use a groovy gradle buildscript.

magneticflux- commented 3 years ago

This has been an issue for ~3 years (if my git blame is correct, it was introduced in https://github.com/FabricMC/fabric-language-scala/commit/1751ea72365964d508250b7ffed61c4ba5405b3b). It was rare enough that we just shrugged it off until now, when some people bothered to get to the bottom of it.

modmuss50 commented 3 years ago

Ok thanks for looking into it. I will take a look ASAP.

Bexin3 commented 2 years ago

This makes me unable to use this mod on m1

sleepy-evelyn commented 1 year ago

This issue is still an absolute pain. Means if a single modpack has one mod that relies on Fabric Language Scala you can't play it