@@ -30,6 +30,14 @@ public class NativeLibraryLoader {
3030 private static final String tempFilePrefix = "librocksdbjni" ;
3131 private static final String tempFileSuffix = Environment .getJniLibraryExtension ();
3232
33+ /**
34+ * If you set the System Property ROCKS_JAVA_DEBUG_NLL can be to true
35+ * messages about attempts to load the native library will be printed
36+ * to std out.
37+ */
38+ private static boolean DEBUG_LOADING =
39+ "true" .equals (System .getProperty ("ROCKS_JAVA_DEBUG_NLL" , "false" ));
40+
3341 /**
3442 * Get a reference to the NativeLibraryLoader
3543 *
@@ -55,14 +63,17 @@ public static NativeLibraryLoader getInstance() {
5563 *
5664 * @throws java.io.IOException if a filesystem operation fails.
5765 */
58- @ SuppressWarnings ("PMD.EmptyCatchBlock" )
66+ @ SuppressWarnings ({ "PMD.EmptyCatchBlock" , "PMD.SystemPrintln" } )
5967 public synchronized void loadLibrary (final String tmpDir ) throws IOException {
6068 try {
6169 // try dynamic library
6270 System .loadLibrary (sharedLibraryName );
6371 return ;
6472 } catch (final UnsatisfiedLinkError ule ) {
6573 // ignore - try from static library
74+ if (DEBUG_LOADING ) {
75+ System .out .println ("Unable to load shared dynamic library: " + sharedLibraryName );
76+ }
6677 }
6778
6879 try {
@@ -71,6 +82,9 @@ public synchronized void loadLibrary(final String tmpDir) throws IOException {
7182 return ;
7283 } catch (final UnsatisfiedLinkError ule ) {
7384 // ignore - then try static library fallback or from jar
85+ if (DEBUG_LOADING ) {
86+ System .out .println ("Unable to load shared static library: " + jniLibraryName );
87+ }
7488 }
7589
7690 if (fallbackJniLibraryName != null ) {
@@ -80,6 +94,10 @@ public synchronized void loadLibrary(final String tmpDir) throws IOException {
8094 return ;
8195 } catch (final UnsatisfiedLinkError ule ) {
8296 // ignore - then try from jar
97+ if (DEBUG_LOADING ) {
98+ System .out .println (
99+ "Unable to load shared static fallback library: " + fallbackJniLibraryName );
100+ }
83101 }
84102 }
85103
@@ -137,13 +155,17 @@ private File createTemp(final String tmpDir, final String libraryFileName) throw
137155 }
138156 }
139157
140- @ SuppressWarnings ({"PMD.UseProperClassLoader" , "PMD.UseTryWithResources" })
158+ @ SuppressWarnings ({"PMD.UseProperClassLoader" , "PMD.UseTryWithResources" , "PMD.SystemPrintln" })
141159 File loadLibraryFromJarToTemp (final String tmpDir ) throws IOException {
142160 try (InputStream is = getClass ().getClassLoader ().getResourceAsStream (jniLibraryFileName )) {
143161 if (is != null ) {
144162 final File temp = createTemp (tmpDir , jniLibraryFileName );
145163 Files .copy (is , temp .toPath (), StandardCopyOption .REPLACE_EXISTING );
146164 return temp ;
165+ } else {
166+ if (DEBUG_LOADING ) {
167+ System .out .println ("Unable to find: " + jniLibraryFileName + " on the classpath" );
168+ }
147169 }
148170 }
149171
@@ -158,6 +180,11 @@ File loadLibraryFromJarToTemp(final String tmpDir) throws IOException {
158180 final File temp = createTemp (tmpDir , fallbackJniLibraryFileName );
159181 Files .copy (is , temp .toPath (), StandardCopyOption .REPLACE_EXISTING );
160182 return temp ;
183+ } else {
184+ if (DEBUG_LOADING ) {
185+ System .out .println (
186+ "Unable to find fallback: " + fallbackJniLibraryFileName + " on the classpath" );
187+ }
161188 }
162189 }
163190
0 commit comments