oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.19k stars 1.62k forks source link

[GR-51123] Native image fails to load a DLL from a path that contains non-ASCII characters #8095

Open petoncle opened 8 months ago

petoncle commented 8 months ago

Native image fails to load a DLL from a path that contains non-ASCII characters... or from a path that contains the ~N tilde notation.

Describe the issue

This is a Windows only issue.

I have an app that uses JNA. JNA initially loads a DLL (jnidispatch.dll) after extracting it into a temporary folder that looks like this: C:\Users\<username>\AppData\Local\Temp\jna--187459531\jna11031635164979162837.dll

If the \<username> contains non-ASCII characters (e.g. José), or if, in addition to containing non-ASCII characters, the username is too long (Alejandría) and Windows uses the \~N tilde notation (C:\Users\Alejan~1\AppData\...), the GraalVM native image fails loading the DLL:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: C:\Users\Alejan~1\AppData\Local\Temp\jna--187459531\jna11031635164979162837.dll
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibraryAbsolute(NativeLibrarySupport.java:100)
        at java.base@21.0.1/java.lang.ClassLoader.loadLibrary(ClassLoader.java:114)
        at java.base@21.0.1/java.lang.Runtime.load0(Runtime.java:852)
        at java.base@21.0.1/java.lang.System.load(System.java:2021)
        at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:1045)
        at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:1015)
        at com.sun.jna.Native.<clinit>(Native.java:221)
        at mousemaster.ExtendedKernel32.<clinit>(ExtendedKernel32.java:7)

Steps to reproduce the issue

To reproduce that problem, I just had to give JNA (-Djna.tmpdir) a path containing the \~N tilde notation.

  1. mkdir C:\Alejandría
  2. cd C:\Alejandría
  3. git clone https://github.com/petoncle/mousemaster .
  4. mvnw clean package
  5. mvnw -Pnative -Dagent package
  6. mv target\mousemaster.exe .
  7. mousemaster.exe -Djna.debug_load=true -Djna.tmpdir=C:\Alejan~1

Describe GraalVM and your environment:

More details

This works (non-native version running with graalvm-jdk-21.0.1+12.1):

C:\Alejandría>C:\graalvm-jdk-21.0.1+12.1\bin\java -Djna.debug_load=true -Djna.tmpdir=C:\Alejan~1 -jar mousemaster.jar
INFO: Found library resource at jar:file:/C:/Alejandr%c3%ada/mousemaster.jar!/com/sun/jna/win32-x86-64/jnidispatch.dll
Dec 26, 2023 4:23:13 PM com.sun.jna.Native extractFromResourcePath
INFO: Extracting library to C:\Alejan~1\jna2218230710365587904.dll
Dec 26, 2023 4:23:13 PM com.sun.jna.NativeLibrary loadLibrary
(...)

This does not work (native image):

C:\Alejandría>mousemaster.exe -Djna.debug_load=true -Djna.tmpdir=C:\Alejan~1
INFO: Found library resource at resource:/com/sun/jna/win32-x86-64/jnidispatch.dll
Dec 26, 2023 4:26:17 PM com.sun.jna.Native extractFromResourcePath
INFO: Extracting library to C:\Alejan~1\jna18325864350615041260.dll
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: C:\Alejan~1\jna18325864350615041260.dll
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibraryAbsolute(NativeLibrarySupport.java:100)
(...)

This works (native image still, \~N tilde notation still, but only ASCII characters: Alejandro):

C:\Alejandro>mousemaster.exe -Djna.debug_load=true -Djna.tmpdir=C:\Alejan~1
INFO: Found library resource at resource:/com/sun/jna/win32-x86-64/jnidispatch.dll
Dec 26, 2023 4:33:13 PM com.sun.jna.Native extractFromResourcePath
INFO: Extracting library to C:\Alejan~1\jna10184328519890257310.dll
Dec 26, 2023 4:33:13 PM com.sun.jna.NativeLibrary loadLibrary
(...)
hamzaGhaissi commented 8 months ago

Thanks For reporting, we are tracking it internally.