Skip to content

Commit

Permalink
chore: Improve error handling when native lib fails to load (#1000)
Browse files Browse the repository at this point in the history
* improve error reporting on errors loading native lib

* make variable volatile
  • Loading branch information
andygrove authored Oct 23, 2024
1 parent cb3e977 commit 845b654
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions common/src/main/java/org/apache/comet/NativeBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,24 @@ public abstract class NativeBase {

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

static {
if (!isLoaded()) {
try {
load();
} catch (Throwable th) {
LOG.warn("Failed to load comet library", th);
// logging may not be initialized yet, so also write to stderr
System.err.println("Failed to load comet library: " + th.getMessage());
loadErr = th;
}
}

public static synchronized boolean isLoaded() {
public static synchronized boolean isLoaded() throws Throwable {
if (loadErr != null) {
throw loadErr;
}
return loaded;
}

Expand Down

0 comments on commit 845b654

Please sign in to comment.