NoSuchMethodError in jna-platform

前提是你 提交于 2020-01-13 20:23:27

问题


I wanna make a new release of the application but when starting it it throws NoSuchMethodError

java.lang.NoSuchMethodError: com.sun.jna.Native.load(Ljava/lang/String;Ljava/lang/Class;Ljava/util/Map;)Lcom/sun/jna/Library;
    at com.sun.jna.platform.win32.Shell32.<clinit>(Shell32.java:45)
    at com.sun.jna.platform.win32.Shell32Util.getFolderPath(Shell32Util.java:54)
    at com.sun.jna.platform.win32.Shell32Util.getFolderPath(Shell32Util.java:71)
    at com.faforever.client.preferences.PreferencesService.<clinit>(PreferencesService.java:78)
    at com.faforever.client.FafClientApplication.main(FafClientApplication.java:55)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:85)
    at com.exe4j.runtime.WinLauncher.main(WinLauncher.java:94)
    at com.install4j.runtime.launcher.WinLauncher.main(WinLauncher.java:25)

Similar to NoSuchMethodError using JNA User32 platform map However I do have version 5.0.0 of both libaries.

It is about this project https://github.com/FAForever/downlords-faf-client it uses gradle as a build tool...

Also I decompiled the installed program and found the method that java claims is not present in the jna libary. Which I find super weird.

Also I check no other dependency has a dependency on jna.

But the thing that is the strangest is it work when I run it all from intelij (oracle jdk 10) but then if I build the installer(openjdk 10 on travis) it does not (same machine).

Also it worked before and we did not change anything about the code related to jna nor the library version. What might have changed is the openjdk version travis uses, but I can not see how that would be related.

Does anybody have an idea what might cause this....

This is the actual code that fails:

Paths.get(Shell32Util.getFolderPath(ShlObj.CSIDL_COMMON_APPDATA), "FAForever")

Even though I thik it is not the problem...

This is the jvm log https://drive.google.com/file/d/11RpxvFubYM7vCoAE-Kx_6EkIKADPQofE/view?usp=sharing

Of which this is probably the important part :

[3.689s][debug][class,resolve               ] com.sun.jna.Native java.lang.Object (super)
[3.689s][debug][class,resolve               ] com.sun.jna.Native com.sun.jna.Version (interface)
[3.689s][debug][class,resolve               ] com.sun.jna.platform.win32.Shell32 com.sun.jna.Native Shell32.java:45 (explicit)
[3.689s][debug][protectiondomain            ] Checking package access
[3.689s][debug][protectiondomain            ] class loader: a 'jdk/internal/loader/ClassLoaders$AppClassLoader'{0x00000000ee70de08} protection domain: a 'java/security/ProtectionDomain'{0x00000000ef103908} loading: 'com/sun/jna/Native'
[3.689s][debug][protectiondomain            ] granted
[3.689s][trace][protectiondomain            ] pd set count = #1
[3.689s][debug][class,resolve               ] com.sun.jna.platform.win32.Shell32 com.sun.jna.Native Shell32.java:45
[3.689s][info ][stacktrace                  ] java.lang.NoSuchMethodError, 12
[3.689s][info ][exceptions                  ] Exception <a 'java/lang/NoSuchMethodError'{0x00000000ef00dd70}: com.sun.jna.Native.load(Ljava/lang/String;Ljava/lang/Class;Ljava/util/Map;)Lcom/sun/jna/Library;> (0x00000000ef00dd70) 
thrown [t:/workspace/open/src/hotspot/share/interpreter/linkResolver.cpp, line 741]
for thread 0x00000000031a5000

Probably the discord library I added also contains jna, see log from jvm:

[3.689s][info ][class,load                  ] com.sun.jna.Native source: file:/E:/DownlordClient%20RC/Downlord's%20FAF%20Client/lib/discord-rpc-1.6.2.jar

回答1:


The NoSuchMethodError related to JNA is almost always related to having an older version of JNA somewhere in your dependency list, even if you also have the current version.

Your comment here gives the hint:

Probably the discord library I added also contains jna, see log from jvm

Looking at that library's POM we see:

<name>DiscordRPC</name>
<version>1.6.2</version>
...
<dependencies>
    <dependency>
        <groupId>net.java.dev.jna</groupId>
        <artifactId>jna</artifactId>
        <version>4.5.1</version>
        <scope>compile</scope>
    </dependency>
    ...
</dependencies>

So you are likely in a situation where Gradle's dependency resolution has chosen to use the older jna even though you have both available, and you likely have jna-platform version 5.0.0 and jna version 4.5.1.

You should update your build script to force use of version 5.0.0 (or more recent) for both jna and jna-platform.



来源:https://stackoverflow.com/questions/55982008/nosuchmethoderror-in-jna-platform

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!