Rethrow NoSuchMethodError with more hints about incompatible native library versions (#10740)
Motivation:
03aafb9cff
did ensure we fail while loading a natibe library which is not compatible. While this is great it is still sometimes hard for people to understand what NoSuchMethodError means in this context.
Modifications:
If possible rethrow the NoSuchMethodError and provide some more hints about multiple versions of the shared library
Result:
Easier to understand for people why loading fails
This commit is contained in:
parent
d4defc30b8
commit
d371b1bbaa
@ -350,6 +350,11 @@ public final class NativeLibraryLoader {
|
||||
}
|
||||
NativeLibraryUtil.loadLibrary(name, absolute); // Fallback to local helper class.
|
||||
logger.debug("Successfully loaded the library {}", name);
|
||||
} catch (NoSuchMethodError nsme) {
|
||||
if (suppressed != null) {
|
||||
ThrowableUtil.addSuppressed(nsme, suppressed);
|
||||
}
|
||||
rethrowWithMoreDetailsIfPossible(name, nsme);
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
if (suppressed != null) {
|
||||
ThrowableUtil.addSuppressed(ule, suppressed);
|
||||
@ -358,6 +363,15 @@ public final class NativeLibraryLoader {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressJava6Requirement(reason = "Guarded by version check")
|
||||
private static void rethrowWithMoreDetailsIfPossible(String name, NoSuchMethodError error) {
|
||||
if (PlatformDependent.javaVersion() >= 7) {
|
||||
throw new LinkageError(
|
||||
"Possible multiple incompatible native libraries on the classpath for '" + name + "'?", error);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
private static void loadLibraryByHelper(final Class<?> helper, final String name, final boolean absolute)
|
||||
throws UnsatisfiedLinkError {
|
||||
Object ret = AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
|
Loading…
Reference in New Issue
Block a user