From 65085c1a2fb85aa2f70823a2af1ac1e6b91288e1 Mon Sep 17 00:00:00 2001 From: David Kocher Date: Sun, 28 Jun 2020 22:39:35 +0200 Subject: [PATCH] Try all frameworks paths regardless of file exist check. > New in macOS Big Sur 11 beta, the system ships with a built-in dynamic linker cache of all system-provided libraries. As part of this change, copies of dynamic libraries are no longer present on the filesystem. Code that attempts to check for dynamic library presence by looking for a file at a path or enumerating a directory will fail. Instead, check for library presence by attempting to dlopen() the path, which will correctly check for the library in the cache. (62986286) Fix #1215. Signed-off-by: David Kocher --- CHANGES.md | 1 + src/com/sun/jna/NativeLibrary.java | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7ceca9538d..aef33453ed 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,7 @@ Bug Fixes * [#1183](https://github.com/java-native-access/jna/pull/1183): `c.s.j.p.win32.WinDef.CHARByReference#getValue` should only read one byte - [@dbwiddis](https://github.com/dbwiddis). * [#1184](https://github.com/java-native-access/jna/pull/1184): `c.s.j.p.win32.WinDef.ULONGLONG` should always be 8 bytes - [@dbwiddis](https://github.com/dbwiddis). * [#1196](https://github.com/java-native-access/jna/pull/1196): `c.s.j.p.win32.WinNT.LARGE_INTEGER` needs to populate both union fields - [@dbwiddis](https://github.com/dbwiddis). +* [#1216](https://github.com/java-native-access/jna/pull/1216): Failure loading frameworks on macOS 11 - [@dkocher](https://github.com/dkocher). Release 5.5.0 ============= diff --git a/src/com/sun/jna/NativeLibrary.java b/src/com/sun/jna/NativeLibrary.java index 6b8eb1fe39..493155a593 100644 --- a/src/com/sun/jna/NativeLibrary.java +++ b/src/com/sun/jna/NativeLibrary.java @@ -242,18 +242,30 @@ else if (Platform.isLinux() || Platform.isFreeBSD()) { } // Search framework libraries on OS X else if (Platform.isMac() && !libraryName.endsWith(".dylib")) { - LOG.log(DEBUG_LOAD_LEVEL, "Looking for matching frameworks"); - libraryPath = matchFramework(libraryName); - if (libraryPath != null) { + if (System.getProperty("os.version").compareTo("10.16") >= 0) { try { - LOG.log(DEBUG_LOAD_LEVEL, "Trying " + libraryPath); - handle = Native.open(libraryPath, openFlags); + LOG.log(DEBUG_LOAD_LEVEL, "Trying " + libraryName); + handle = Native.open(libraryName, openFlags); } catch(UnsatisfiedLinkError e2) { LOG.log(DEBUG_LOAD_LEVEL, "Loading failed with message: " + e2.getMessage()); exceptions.add(e2); } } + else { + LOG.log(DEBUG_LOAD_LEVEL, "Looking for matching frameworks"); + libraryPath = matchFramework(libraryName); + if (libraryPath != null) { + try { + LOG.log(DEBUG_LOAD_LEVEL, "Trying " + libraryPath); + handle = Native.open(libraryPath, openFlags); + } + catch(UnsatisfiedLinkError e2) { + LOG.log(DEBUG_LOAD_LEVEL, "Loading failed with message: " + e2.getMessage()); + exceptions.add(e2); + } + } + } } // Try the same library with a "lib" prefix else if (Platform.isWindows() && !isAbsolutePath) {