Skip to content

Commit 845b654

Browse files
authored
chore: Improve error handling when native lib fails to load (apache#1000)
* improve error reporting on errors loading native lib * make variable volatile
1 parent cb3e977 commit 845b654

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎common/src/main/java/org/apache/comet/NativeBase.java‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,24 @@ public abstract class NativeBase {
4646

4747
private static final String libraryToLoad = System.mapLibraryName(NATIVE_LIB_NAME);
4848
private static boolean loaded = false;
49+
private static volatile Throwable loadErr = null;
4950
private static final String searchPattern = "libcomet-";
5051

5152
static {
52-
if (!isLoaded()) {
53+
try {
5354
load();
55+
} catch (Throwable th) {
56+
LOG.warn("Failed to load comet library", th);
57+
// logging may not be initialized yet, so also write to stderr
58+
System.err.println("Failed to load comet library: " + th.getMessage());
59+
loadErr = th;
5460
}
5561
}
5662

57-
public static synchronized boolean isLoaded() {
63+
public static synchronized boolean isLoaded() throws Throwable {
64+
if (loadErr != null) {
65+
throw loadErr;
66+
}
5867
return loaded;
5968
}
6069

0 commit comments

Comments
 (0)