Skip to content

Commit

Permalink
Use correct native library on OpenJDK on AIX
Browse files Browse the repository at this point in the history
It seems System#mapLibraryName from OpenJDK works differently on AIX
than OpenJ9. OpenJ9 expands jnidispatch to libjnidispatch.a, while
OpenJDK expands it to libjnidispatch.so. This in turn causes the
loader to search for the wrong file.

java-native-access#1066

Closes: java-native-access#1066
  • Loading branch information
matthiasblaesing committed Feb 15, 2019
1 parent e0d5537 commit 57a4b96
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Bug Fixes
---------
* [#1052](https://github.com/java-native-access/jna/pull/1052), [#1053](https://github.com/java-native-access/jna/issues/1053): WinXP compatibility for `c.s.j.p.win32.PdhUtil` - [@dbwiddis](https://github.com/dbwiddis).
* [#1055](https://github.com/java-native-access/jna/pull/1055): Include `c.s.j.p.linux` in OSGi bundle. - [@dbwiddis](https://github.com/dbwiddis).
* [#1066](https://github.com/java-native-access/jna/issues/1066): On AIX OpenJDK differs from IBM J9 in the mapping of library names. While J9 maps jnidispatch to `libjnidispatch.a`, OpenJDK maps to `libjnidispatch.so`, which causes the native library extractor to fail. AIX is now hard-coded to `libjnidispatch.a` - [@matthiasblaesing](https://github.com/matthiasblaesing).

Release 5.2.0
=============
Expand Down
8 changes: 7 additions & 1 deletion src/com/sun/jna/Native.java
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,13 @@ private static void loadNativeDispatchLibrary() {
*/
private static void loadNativeDispatchLibraryFromClasspath() {
try {
String libName = "/com/sun/jna/" + Platform.RESOURCE_PREFIX + "/" + System.mapLibraryName("jnidispatch").replace(".dylib", ".jnilib");
String mappedName = System.mapLibraryName("jnidispatch").replace(".dylib", ".jnilib");
if(Platform.isAIX()) {
// OpenJDK is reported to map to .so -- this works around the
// difference between J9 and OpenJDK
mappedName = "libjnidispatch.a";
}
String libName = "/com/sun/jna/" + Platform.RESOURCE_PREFIX + "/" + mappedName;
File lib = extractFromResourcePath(libName, Native.class.getClassLoader());
if (lib == null) {
if (lib == null) {
Expand Down

0 comments on commit 57a4b96

Please sign in to comment.