Fix UnsupportedOperationException on Windows in JNI* loaders#38
Conversation
On Windows (NTFS), Files.createTempFile with POSIX file attributes throws:
UnsupportedOperationException: 'posix:permissions' not supported as initial attribute
This crash prevents JNIBLAS, JNILAPACK, and JNIARPACK from loading on any
Windows JVM, silently falling back to the pure-Java implementation.
Fix: guard the POSIX attribute with a FileSystems.getDefault() check, which
returns an empty attribute array on non-POSIX filesystems (Windows/NTFS).
Also add Windows os.name normalisation ("windows") and .dll extension to
match the existing macOS pattern.
Affected files: JNIBLAS.java, JNILAPACK.java, JNIARPACK.java
|
I’m surprised this works even with the change given that it’s still missing the native JNI shim that sits between the Java code and the native library (the jni.c files for each of blas, lapack, arpack). Would you be interested in adding support for Windows on CI as well? I can always ask Claude otherwise. |
|
I compiled the native shim for my testing. Although Happy to help out if I can ... |
|
Let's merge it as-is for now, and we can work on having the native wrapper in a follow up PR |
Let me know if this isn't what you require: #39 |
Problem
On Windows (NTFS),
JNIBLAS,JNILAPACK, andJNIARPACKall crash during initialisation with:This is thrown by
Files.createTempFile(prefix, suffix, PosixFilePermissions.asFileAttribute(...))because NTFS does not support POSIX file attributes. The exception is caught by theInstanceBuilderfallback chain, so on Windows the JNI native backend silently never loads and every caller fallsback to the pure-Java implementation.
Root cause
Three places in the code unconditionally pass a POSIX
FileAttributetoFiles.createTempFile:blas/src/main/java/dev/ludovic/netlib/blas/JNIBLAS.javalapack/src/main/java/dev/ludovic/netlib/lapack/JNILAPACK.javaarpack/src/main/java/dev/ludovic/netlib/arpack/JNIARPACK.javaFix
Guard the attribute with a
FileSystems.getDefault().supportedFileAttributeViews().contains("posix")check — the same portable idiom used elsewhere in the JDK ecosystem. On non-POSIX filesystems (Windows/NTFS) this returns an emptyFileAttribute<?>[], whichFiles.createTempFileaccepts fine.Also adds the existing macOS pattern of
os.namenormalisation and.dllextension for Windows, so the correct resource pathresources/native/windows-amd64/libnetlibblasjni.dllis resolved when a Windows native DLL is bundled in the JAR.Testing
Verified on Windows 11 / MSYS2 / JVM 21 with Breeze 2.1.0:
JNIBLAS: 'posix:permissions' not supported as initial attribute→ falls back to VECTORAPIBLASINFO: Using dev.ludovic.netlib.blas.JNIBLAS→ native OpenBLAS loadedRelates to #20.