Skip to content

Migrate from JNA to jnr-posix for native POSIX operations#271

Merged
fglock merged 1 commit into
masterfrom
migrate-jna-to-jnr-posix
Mar 5, 2026
Merged

Migrate from JNA to jnr-posix for native POSIX operations#271
fglock merged 1 commit into
masterfrom
migrate-jna-to-jnr-posix

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Mar 5, 2026

Summary

  • Replace JNA 5.18.1 (which uses deprecated sun.misc.Unsafe::staticFieldBase) with jnr-posix 3.1.19 for POSIX operations and pure Java APIs for Windows
  • Eliminates both jna and jna-platform dependencies
  • Net change: -1052 lines, +211 lines across 15 files

Key changes

  • PosixLibrary: rewritten as thin wrapper around POSIXFactory.getNativePOSIX()
  • WindowsLibrary: gutted (was entirely unused — no callers existed)
  • NativeUtils: Windows kill uses ProcessHandle.destroy(), platform detection via System.getProperty("os.name") instead of JNA Platform class
  • ExtendedNativeUtils: uses jnr.posix.Passwd instead of raw Pointer parsing
  • Stat: uses jnr.posix.FileStat instead of Memory/Pointer parsing
  • KillOperator: Windows uses ProcessHandle, POSIX uses jnr-posix kill() + errno()
  • UtimeOperator: POSIX uses jnr-posix utimes(), Windows uses pure Java NIO
  • WaitpidOperator: Windows uses Process/ProcessHandle, POSIX uses int[]
  • Operator: Windows chmod uses Files.setAttribute("dos:readonly", ...)
  • Removed 19 unused PosixLibrary method declarations (fork, execve, signal, etc.)
  • Removed dead registerWindowsChildProcess code
  • Added --enable-native-access=ALL-UNNAMED to jperl.bat

Test plan

  • ./gradlew build passes (unit tests)
  • make test passes
  • make test-all — 45.2% pass rate consistent with pre-existing baseline, no regressions from migration
  • Native-operation tests verified: stat_errors.t (638/638), io/fs.t (53/61), fork.t, waitpid.t, glob.t (17/18), kill0.t (6/9)
  • Zero references to com.sun.jna remain in codebase
  • Windows CI (pure Java fallbacks for kill/chmod/utime)

Generated with Devin

Replace JNA 5.18.1 (which uses deprecated sun.misc.Unsafe::staticFieldBase)
with jnr-posix 3.1.19 for POSIX operations and pure Java APIs for Windows.

- PosixLibrary: rewritten as thin wrapper around POSIXFactory.getNativePOSIX()
- WindowsLibrary: gutted (was entirely unused)
- NativeUtils: Windows kill uses ProcessHandle.destroy(), platform detection
  via System.getProperty("os.name") instead of JNA Platform class
- ExtendedNativeUtils: uses jnr.posix.Passwd instead of raw Pointer parsing
- Stat: uses jnr.posix.FileStat instead of Memory/Pointer parsing
- KillOperator: Windows uses ProcessHandle, POSIX uses jnr-posix kill+errno
- UtimeOperator: POSIX uses jnr-posix utimes(), Windows uses pure Java NIO
- WaitpidOperator: Windows uses Process/ProcessHandle, POSIX uses int[]
- Operator: Windows chmod uses Files.setAttribute("dos:readonly")
- Removed 19 unused PosixLibrary method declarations (fork, execve, etc.)
- Removed dead registerWindowsChildProcess code
- Added --enable-native-access=ALL-UNNAMED to jperl.bat

Net: -1052 lines, +211 lines across 15 files. All existing tests pass.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
@fglock fglock merged commit 5de0887 into master Mar 5, 2026
2 checks passed
@fglock fglock deleted the migrate-jna-to-jnr-posix branch March 5, 2026 21:59
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.

1 participant