Bug#734599: libsnappy-java: Fails with FAILED_TO_LOAD_NATIVE_LIBRARY

Alexandros Kosiaris akosiaris at gmail.com
Wed Jan 8 12:42:56 UTC 2014


Package: libsnappy-java
Version: 1.0.4.1~dfsg-1
Severity: grave
Tags: patch
Justification: renders package unusable

Dear Maintainer,

Apologies if this the wrong package to open a bug against, I was unsure whether
I should open it against libsnappy-java or libsnappy1, feel free to
reassign it if needed

While trying to use the simple example from the snappy-java documentation
attached below I encountered an error of FAILED_LOAD_NATIVE_LIBRARY. After a
lot of reading it seems like the upstream ships compiled versions of shared
object (.so) files for various OSes and architectures that get included in the
shipped jar file. Those are stripped out in the Debian package and a dependency
to the libsnappy1 package is declared. That is a nice approach IMHO
However, the .so file shipped by the libsnappy1 package
(/usr/lib/libsnappy.so.1.1.3) does not contain the necessary JNI bindings and
as a result the JNI calls from the Java code fail.

I have managed to bypass the problem by recompiling the libsnappy1 package
with the JNI bindings provided in the libsnappy-java package. I attach the
patch. I am not sure however if this is the best possible solution. It is
however a relatively clean one. Of course this solution is against the
libsnappy1 package and not the libsnappy-java package

Reproduce with:

SnappyTests.java:

import org.xerial.snappy.Snappy;
import java.lang.String;
import java.lang.System;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

class SnappyTests {
public static void main(String[] args) throws
UnsupportedEncodingException, IOException {
String input = "Hello snappy-java! Snappy-java is a JNI-based wrapper of "
    + "Snappy, a fast compresser/decompresser.";
byte[] compressed = Snappy.compress(input.getBytes("UTF-8"));
byte[] uncompressed = Snappy.uncompress(compressed);

String result = new String(uncompressed, "UTF-8");
System.out.println(result);
}
}

Compile with:

javac -cp /usr/share/java/snappy-java.jar SnappyTests.java

Run with:

java -cp '/usr/share/java/snappy-java.jar:.' SnappyTests

Stacktrace returned is:

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.xerial.snappy.SnappyLoader.loadNativeLibrary(SnappyLoader.java:317)
at org.xerial.snappy.SnappyLoader.load(SnappyLoader.java:219)
at org.xerial.snappy.Snappy.<clinit>(Snappy.java:44)
at SnappyTests.main(SnappyTests.java:11)
Caused by: java.lang.UnsatisfiedLinkError: no snappyjava in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1856)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)
at org.xerial.snappy.SnappyNativeLoader.loadLibrary(SnappyNativeLoader.java:52)
... 8 more
Exception in thread "main" org.xerial.snappy.SnappyError:
[FAILED_TO_LOAD_NATIVE_LIBRARY] null
at org.xerial.snappy.SnappyLoader.load(SnappyLoader.java:229)
at org.xerial.snappy.Snappy.<clinit>(Snappy.java:44)
at SnappyTests.main(SnappyTests.java:11)

-- System Information:
Debian Release: 7.3
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.11-0.bpo.2-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.utf8, LC_CTYPE=en_US.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
-------------- next part --------------
A non-text attachment was scrubbed...
Name: snappy.patch
Type: text/x-patch
Size: 15818 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/pkg-java-maintainers/attachments/20140108/a687b772/attachment.bin>


More information about the pkg-java-maintainers mailing list