Skip to content

Commit bfea85b

Browse files
authored
NPE in NativeLibrary when unpacking from classpath is disabled
When a native library is packed into a .jar, but unpacking is disabled (`jna.nounpack = true`), `Native#extractFromResourcePath` returns `null`.
1 parent 529b716 commit bfea85b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/com/sun/jna/NativeLibrary.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,15 @@ else if (Platform.isWindows() && !isAbsolutePath) {
279279
if (handle == 0) {
280280
try {
281281
File embedded = Native.extractFromResourcePath(libraryName, (ClassLoader)options.get(Library.OPTION_CLASSLOADER));
282-
try {
283-
handle = Native.open(embedded.getAbsolutePath(), openFlags);
284-
libraryPath = embedded.getAbsolutePath();
285-
} finally {
286-
// Don't leave temporary files around
287-
if (Native.isUnpacked(embedded)) {
288-
Native.deleteLibrary(embedded);
282+
if (embedded != null) {
283+
try {
284+
handle = Native.open(embedded.getAbsolutePath(), openFlags);
285+
libraryPath = embedded.getAbsolutePath();
286+
} finally {
287+
// Don't leave temporary files around
288+
if (Native.isUnpacked(embedded)) {
289+
Native.deleteLibrary(embedded);
290+
}
289291
}
290292
}
291293
}

0 commit comments

Comments
 (0)