Skip to content

Commit 473b638

Browse files
committed
Improve aec and blosc2 native loading
Handle the case where the native library shipped inside the native jar is not compatible with the current OS's toolchain (e.g., the GLIB_C version associated with the native library is newer than the system supports). In such cases, fall back to searching the system path.
1 parent f9e281a commit 473b638

File tree

2 files changed

+24
-8
lines changed
  • native-compression
    • libaec-jna/src/main/java/edu/ucar/unidata/compression/jna/libaec
    • libblosc2-jna/src/main/java/edu/ucar/unidata/compression/jna/libblosc2

2 files changed

+24
-8
lines changed

native-compression/libaec-jna/src/main/java/edu/ucar/unidata/compression/jna/libaec/LibAec.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025 University Corporation for Atmospheric Research/Unidata
2+
* Copyright (c) 2025-2026 University Corporation for Atmospheric Research/Unidata
33
* See LICENSE for license information.
44
*/
55

@@ -34,13 +34,21 @@ public final class LibAec {
3434
File library = Native.extractFromResourcePath(libName);
3535
Native.register(library.getAbsolutePath());
3636
log.debug("Using libaec library from libaec-native.jar");
37-
} catch (IOException e) {
37+
} catch (IOException | UnsatisfiedLinkError e) {
38+
boolean unusableNativeLib = false;
39+
// The native jar wasn't found on the classpath, OR the native library
40+
// shipped with the jar is not compatible with the current OS toolchain.
41+
// Check for the library on the system path.
42+
if (e instanceof UnsatisfiedLinkError) {
43+
unusableNativeLib = true;
44+
log.debug("Error loading libaec from native jar: {}", e.getMessage());
45+
}
3846
try {
3947
Native.register(libName);
4048
log.debug("Using libaec library from system");
4149
} catch (UnsatisfiedLinkError ule) {
42-
String message =
43-
"libaec C library not present. To read this data, include the libaec-native jar in your classpath "
50+
String message = unusableNativeLib ? "Usable libaec C library not found. Install libaec on your system."
51+
: "libaec C library not found. To read this data, include the libaec-native jar in your classpath "
4452
+ "(edu.ucar:libaec-native) or install libaec on your system.";
4553
log.error(message);
4654
throw new RuntimeException(message, ule);

native-compression/libblosc2-jna/src/main/java/edu/ucar/unidata/compression/jna/libblosc2/LibBlosc2.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025 University Corporation for Atmospheric Research/Unidata
2+
* Copyright (c) 2025-2026 University Corporation for Atmospheric Research/Unidata
33
* See LICENSE for license information.
44
*/
55

@@ -39,13 +39,21 @@ public final class LibBlosc2 {
3939
File library = Native.extractFromResourcePath(libName);
4040
Native.register(library.getAbsolutePath());
4141
log.debug("Using blosc2 library from libblosc2-native.jar");
42-
} catch (IOException e) {
42+
} catch (IOException | UnsatisfiedLinkError e) {
43+
boolean unusableNativeLib = false;
44+
// The native jar wasn't found on the classpath, OR the native library
45+
// shipped with the jar is not compatible with the current OS toolchain.
46+
// Check for the library on the system path.
47+
if (e instanceof UnsatisfiedLinkError) {
48+
unusableNativeLib = true;
49+
log.debug("Error loading libblosc2 from native jar: {}", e.getMessage());
50+
}
4351
try {
4452
Native.register(libName);
4553
log.debug("Using libblosc2 library from system");
4654
} catch (UnsatisfiedLinkError ule) {
47-
String message =
48-
"libblosc2 C library not present. To read this data, include the libblosc2-native jar in your classpath "
55+
String message = unusableNativeLib ? "Usable libblosc2 C library not found. Install libblosc2 on your system."
56+
: "libblosc2 C library not found. To read this data, include the libblosc2-native jar in your classpath "
4957
+ "(edu.ucar:libblosc2-native) or install libblosc2 on your system.";
5058
log.error(message);
5159
throw new RuntimeException(message, ule);

0 commit comments

Comments
 (0)