Skip to content

Commit 491d800

Browse files
committed
8293659: Improve UnsatisfiedLinkError error message to include dlopen error details
Reviewed-by: mchung Backport-of: da4fdfbbf4ba72ddaf4f27d95f71e95b7ebf8cc1
1 parent 525b9fc commit 491d800

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,21 @@ boolean open() {
385385
throw new InternalError("Native library " + name + " has been loaded");
386386
}
387387

388-
return load(this, name, isBuiltin, isJNI, loadLibraryOnlyIfPresent);
388+
return load(this, name, isBuiltin, isJNI, throwExceptionIfFail());
389+
}
390+
391+
@SuppressWarnings("removal")
392+
private boolean throwExceptionIfFail() {
393+
if (loadLibraryOnlyIfPresent) return true;
394+
395+
// If the file exists but fails to load, UnsatisfiedLinkException thrown by the VM
396+
// will include the error message from dlopen to provide diagnostic information
397+
return AccessController.doPrivileged(new PrivilegedAction<>() {
398+
public Boolean run() {
399+
File file = new File(name);
400+
return file.exists();
401+
}
402+
});
389403
}
390404
}
391405

0 commit comments

Comments
 (0)