Skip to content

Fix UnsupportedOperationException on Windows in JNI* loaders#38

Merged
luhenry merged 1 commit intoluhenry:masterfrom
philwalk:fix/windows-jni-loader-posix-attrs
Mar 19, 2026
Merged

Fix UnsupportedOperationException on Windows in JNI* loaders#38
luhenry merged 1 commit intoluhenry:masterfrom
philwalk:fix/windows-jni-loader-posix-attrs

Conversation

@philwalk
Copy link
Contributor

Problem

On Windows (NTFS), JNIBLAS, JNILAPACK, and JNIARPACK all crash during initialisation with:

java.lang.UnsupportedOperationException: 'posix:permissions' not supported as initial attribute

This is thrown by Files.createTempFile(prefix, suffix, PosixFilePermissions.asFileAttribute(...)) because NTFS does not support POSIX file attributes. The exception is caught by the InstanceBuilder fallback chain, so on Windows the JNI native backend silently never loads and every caller falls
back to the pure-Java implementation.

Root cause

Three places in the code unconditionally pass a POSIX FileAttribute to Files.createTempFile:

  • blas/src/main/java/dev/ludovic/netlib/blas/JNIBLAS.java
  • lapack/src/main/java/dev/ludovic/netlib/lapack/JNILAPACK.java
  • arpack/src/main/java/dev/ludovic/netlib/arpack/JNIARPACK.java

Fix

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 empty FileAttribute<?>[], which Files.createTempFile accepts fine.

Also adds the existing macOS pattern of os.name normalisation and .dll extension for Windows, so the correct resource path resources/native/windows-amd64/libnetlibblasjni.dll is resolved when a Windows native DLL is bundled in the JAR.

Testing

Verified on Windows 11 / MSYS2 / JVM 21 with Breeze 2.1.0:

  • Before: JNIBLAS: 'posix:permissions' not supported as initial attribute → falls back to VECTORAPIBLAS
  • After: INFO: Using dev.ludovic.netlib.blas.JNIBLAS → native OpenBLAS loaded

Relates to #20.

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
@luhenry
Copy link
Owner

luhenry commented Mar 18, 2026

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.

@philwalk
Copy link
Contributor Author

I compiled the native shim for my testing.
We use netlib for benchmarking uni.MatD against breeze.

Although netlib is 50% faster than org.bytedeco" % "openblas-platform" (on 512x512 matrix multiply), it's not as user-friendly without a bundled native dll.

Happy to help out if I can ...

@luhenry
Copy link
Owner

luhenry commented Mar 19, 2026

Let's merge it as-is for now, and we can work on having the native wrapper in a follow up PR

@luhenry luhenry merged commit 14e9de3 into luhenry:master Mar 19, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants