8293659: Improve UnsatisfiedLinkError error message to include dlopen error details

Reviewed-by: mchung, lucy
This commit is contained in:
Matthias Baesken 2022-09-21 11:32:24 +00:00
parent cd1cdcdb0d
commit da4fdfbbf4

@ -328,7 +328,21 @@ public final class NativeLibraries {
throw new InternalError("Native library " + name + " has been loaded");
}
return load(this, name, isBuiltin, loadLibraryOnlyIfPresent);
return load(this, name, isBuiltin, throwExceptionIfFail());
}
@SuppressWarnings("removal")
private boolean throwExceptionIfFail() {
if (loadLibraryOnlyIfPresent) return true;
// If the file exists but fails to load, UnsatisfiedLinkException thrown by the VM
// will include the error message from dlopen to provide diagnostic information
return AccessController.doPrivileged(new PrivilegedAction<>() {
public Boolean run() {
File file = new File(name);
return file.exists();
}
});
}
/*