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 committed Dec 2, 2022
1 parent 529b716 commit bdc56e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Bug Fixes
* [#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).
* [#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).
* [#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).
* [#1481](https://github.com/java-native-access/jna/issues/1481): Fix NPE in NativeLibrary when unpacking from classpath is disabled

Release 5.12.1
==============
Expand Down
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 bdc56e4

Please sign in to comment.