From 3156f4a3c3dda2bc13774e049c06c7f6030f160d Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Sun, 12 Apr 2026 16:34:18 -0700 Subject: [PATCH] Fix UdevDevice.getSysname() calling udev_device_get_syspath instead of udev_device_get_sysname UdevDevice.getSysname() was calling udev_device_get_syspath instead of udev_device_get_sysname due to a copy-paste error. Fix: getSysname() now calls udev_device_get_sysname. Test: added assertion that sysname is strictly shorter than syspath, which would have caught this originally. --- CHANGES.md | 1 + contrib/platform/src/com/sun/jna/platform/linux/Udev.java | 2 +- .../platform/test/com/sun/jna/platform/linux/UdevTest.java | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d025076e56..4396c32604 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ Features Bug Fixes --------- * [#1644](https://github.com/java-native-access/jna/issues/1644): Fix bug in VARDESC and TYPEDESC causing an illegal memory access - [@lwahonen](https://github.com/lwahonen) +* [#1715](https://github.com/java-native-access/jna/pull/1715): Fix `UdevDevice.getSysname()` calling `udev_device_get_syspath` instead of `udev_device_get_sysname` - [@dbwiddis](https://github.com/dbwiddis). Release 5.18.1 ============== diff --git a/contrib/platform/src/com/sun/jna/platform/linux/Udev.java b/contrib/platform/src/com/sun/jna/platform/linux/Udev.java index a9dd758a2b..c42cb1ba37 100644 --- a/contrib/platform/src/com/sun/jna/platform/linux/Udev.java +++ b/contrib/platform/src/com/sun/jna/platform/linux/Udev.java @@ -233,7 +233,7 @@ public String getSyspath() { * @return a string that describes the sysname. On failure, may return NULL. */ public String getSysname() { - return INSTANCE.udev_device_get_syspath(this); + return INSTANCE.udev_device_get_sysname(this); } /** diff --git a/contrib/platform/test/com/sun/jna/platform/linux/UdevTest.java b/contrib/platform/test/com/sun/jna/platform/linux/UdevTest.java index 5724a176a3..8ea89b83e8 100644 --- a/contrib/platform/test/com/sun/jna/platform/linux/UdevTest.java +++ b/contrib/platform/test/com/sun/jna/platform/linux/UdevTest.java @@ -111,7 +111,9 @@ public void testEnumerateDevices() { assertEquals(String.format("DevType mismatch (%s)", devnode), devType, device.getDevtype()); assertEquals(String.format("Subsystem mismatch (%s)", devnode), "block", device.getSubsystem()); assertEquals(String.format("Syspath mismatch (%s)", devnode), syspath, device.getSyspath()); - assertTrue(String.format("Syspath should end with name (%s)", devnode), syspath.endsWith(device.getSysname())); + String sysname = device.getSysname(); + assertTrue(String.format("Syspath should end with name (%s)", devnode), syspath.endsWith(sysname)); + assertTrue(String.format("Sysname should be shorter than syspath (%s)", devnode), sysname.length() < syspath.length()); } } finally { // Release the reference and iterate to the next device