Skip to content

Commit bdc56e4

Browse files
committed
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 bdc56e4

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Bug Fixes
1717
* [#1452](https://github.com/java-native-access/jna/issues/1452): Fix memory allocation/handling for error message generation in native library code (`dispatch.c`) - [@matthiasblaesing](https://github.com/matthiasblaesing).
1818
* [#1460](https://github.com/java-native-access/jna/issues/1460): Fix win32 variant date conversion in DST offest window and with millisecond values - [@eranl](https://github.com/eranl).
1919
* [#1472](https://github.com/java-native-access/jna/issues/1472): Fix incorrect bitmask in `c.s.j.Pointer#createConstant(int)` - [@dbwiddis](https://github.com/dbwiddis).
20+
* [#1481](https://github.com/java-native-access/jna/issues/1481): Fix NPE in NativeLibrary when unpacking from classpath is disabled
2021

2122
Release 5.12.1
2223
==============

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)