Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8213772

System.loadLibrary does not honor `java.library.path` for dependent libraries

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8, 10.0.2, 11
    • Fix Version/s: None
    • Component/s: core-libs

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10, 64bit
      Tested on JDK 1.8u192 32bit (because dlls are 32bit)
      Tested on JDK 10.0.2 32bit
      Can't test JDK11, I don't have 64bit dlls

      A DESCRIPTION OF THE PROBLEM :
      When calling System.loadLibrary on a DLL found in the location set by -Djava.library.path, the native loader does not include that in it's search path for when looking for dependent libraries.

      Given the following
      project
      |_dlls
        |_ A.dll
        |_ B.dll

      and starting an application such as:

      java -Djava.library.path=project/dlls TestNativeLibraries

      You get the error "Caused by: java.lang.UnsatisfiedLinkError: C:\project\dlls\A.dll: Can't find dependent libraries"
      When A,dll depends on B.dll.

      The JVM's nativeLoader searches all locations in %PATH%, including the CWD and for some reason, the User's Desktop, but it does not include the path associated with `java.library.path`

      The error message could also be more helpful, and include which libraries it was unable to load. Since I was new to this, I assume it couldn't find the required OS libraries because when you set `java.library.path` is clears the values the JVM picks up from the %PATH%. But this was not the case. Using Microsoft's ProcMon to trace the system calls, it was finally clear that the JVM simply ignored the `java.library.path` when searching for B.dll



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) get two dlls files, A.dll that depends on B.dll
      2) Set java.library.path so a location that holds these dlls, that is NOT on the %PATH%
      3) Call System.loadLibrary("A.dll")
      4) You have reproduced the issue!

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      For the Native Loader to include the value of java.library.path in it's search locations when looking for dependent libraries for native libraries loaded via System.loadLibrary
      ACTUAL -
      It doesn't

      ---------- BEGIN SOURCE ----------
      public class NativeTest {
          public static void main(String[] args) {
              System.out.println("Path:" + System.getProperty("java.library.path"));
              System.loadLibrary("A");
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Call System.loadLibrary("B")... then System.loadLibrary("A")

      It's hacky, but it works, but it was extremely hard to figure out that you need to do this with the current error messaging and based on the documentation of java.library.path

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bchristi Brent Christian
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: