Skip to content

Commit da4fdfb

Browse files
committed
8293659: Improve UnsatisfiedLinkError error message to include dlopen error details
Reviewed-by: mchung, lucy
1 parent cd1cdcd commit da4fdfb

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
@@ -328,7 +328,21 @@ boolean open() {
328328
throw new InternalError("Native library " + name + " has been loaded");
329329
}
330330

331-
return load(this, name, isBuiltin, loadLibraryOnlyIfPresent);
331+
return load(this, name, isBuiltin, throwExceptionIfFail());
332+
}
333+
334+
@SuppressWarnings("removal")
335+
private boolean throwExceptionIfFail() {
336+
if (loadLibraryOnlyIfPresent) return true;
337+
338+
// If the file exists but fails to load, UnsatisfiedLinkException thrown by the VM
339+
// will include the error message from dlopen to provide diagnostic information
340+
return AccessController.doPrivileged(new PrivilegedAction<>() {
341+
public Boolean run() {
342+
File file = new File(name);
343+
return file.exists();
344+
}
345+
});
332346
}
333347

334348
/*

0 commit comments

Comments
 (0)