Skip to content

Commit

Permalink
NPE in NativeLibrary when unpacking from classpath is disabled
Browse files Browse the repository at this point in the history
When a native library is packed into a .jar, but unpacking is disabled (`jna.nounpack = true`), `Native#extractFromResourcePath` returns `null`.
  • Loading branch information
trespasserw authored Nov 30, 2022
1 parent 529b716 commit bfea85b
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/com/sun/jna/NativeLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,15 @@ else if (Platform.isWindows() && !isAbsolutePath) {
if (handle == 0) {
try {
File embedded = Native.extractFromResourcePath(libraryName, (ClassLoader)options.get(Library.OPTION_CLASSLOADER));
try {
handle = Native.open(embedded.getAbsolutePath(), openFlags);
libraryPath = embedded.getAbsolutePath();
} finally {
// Don't leave temporary files around
if (Native.isUnpacked(embedded)) {
Native.deleteLibrary(embedded);
if (embedded != null) {
try {
handle = Native.open(embedded.getAbsolutePath(), openFlags);
libraryPath = embedded.getAbsolutePath();
} finally {
// Don't leave temporary files around
if (Native.isUnpacked(embedded)) {
Native.deleteLibrary(embedded);
}
}
}
}
Expand Down

0 comments on commit bfea85b

Please sign in to comment.