Skip to content

Commit 83d2776

Browse files
committed
Add Java System Property 'ROCKS_JAVA_DEBUG_NLL' to enable debugging of NativeLibraryLoader
1 parent 641446a commit 83d2776

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

java/src/main/java/org/rocksdb/NativeLibraryLoader.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ 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 = "true".equals(System.getProperty("ROCKS_JAVA_DEBUG_NLL", "false"));
39+
3340
/**
3441
* Get a reference to the NativeLibraryLoader
3542
*
@@ -63,6 +70,9 @@ public synchronized void loadLibrary(final String tmpDir) throws IOException {
6370
return;
6471
} catch (final UnsatisfiedLinkError ule) {
6572
// ignore - try from static library
73+
if (DEBUG_LOADING) {
74+
System.out.println("Unable to load shared dynamic library: " + sharedLibraryName);
75+
}
6676
}
6777

6878
try {
@@ -71,6 +81,9 @@ public synchronized void loadLibrary(final String tmpDir) throws IOException {
7181
return;
7282
} catch (final UnsatisfiedLinkError ule) {
7383
// ignore - then try static library fallback or from jar
84+
if (DEBUG_LOADING) {
85+
System.out.println("Unable to load shared static library: " + jniLibraryName);
86+
}
7487
}
7588

7689
if (fallbackJniLibraryName != null) {
@@ -80,6 +93,9 @@ public synchronized void loadLibrary(final String tmpDir) throws IOException {
8093
return;
8194
} catch (final UnsatisfiedLinkError ule) {
8295
// ignore - then try from jar
96+
if (DEBUG_LOADING) {
97+
System.out.println("Unable to load shared static fallback library: " + fallbackJniLibraryName);
98+
}
8399
}
84100
}
85101

@@ -144,6 +160,10 @@ File loadLibraryFromJarToTemp(final String tmpDir) throws IOException {
144160
final File temp = createTemp(tmpDir, jniLibraryFileName);
145161
Files.copy(is, temp.toPath(), StandardCopyOption.REPLACE_EXISTING);
146162
return temp;
163+
} else {
164+
if (DEBUG_LOADING) {
165+
System.out.println("Unable to find: " + jniLibraryFileName + " on the classpath");
166+
}
147167
}
148168
}
149169

@@ -157,6 +177,10 @@ File loadLibraryFromJarToTemp(final String tmpDir) throws IOException {
157177
final File temp = createTemp(tmpDir, fallbackJniLibraryFileName);
158178
Files.copy(is, temp.toPath(), StandardCopyOption.REPLACE_EXISTING);
159179
return temp;
180+
} else {
181+
if (DEBUG_LOADING) {
182+
System.out.println("Unable to find fallback: " + fallbackJniLibraryFileName + " on the classpath");
183+
}
160184
}
161185
}
162186

0 commit comments

Comments
 (0)