-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Improve error handling when native lib fails to load #1000
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is called from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correction: calling isLoaded could have resulted in the |
||
if (loadErr != null) { | ||
throw loadErr; | ||
} | ||
return loaded; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
load
is a no-op ifloaded == false
so no need for this conditional here