zeromq / jzmq

Java binding for ZeroMQ
http://www.zeromq.org
GNU General Public License v3.0
589 stars 363 forks source link

Embedded libraries are not always loaded before they are needed #453

Closed jcoeltjen closed 7 years ago

jcoeltjen commented 7 years ago

When using a Class that makes calls to the native API an UnsatisfiedLinkError will occur because the embedded libraries have not been loaded properly.

The embedded libraries are loaded when the ZMQ class is loaded (in its static{} block. But when trying to use a class that makes native calls (e.g. ZMQ.Curve) the static block of ZMQ will not be executed. Therefore no native libraries are loaded and the call to create a CURVE key pair will fail (as it is a call to a native library).

TODO:

Failing code example:

@Test
public void unsatisfiedLinkError() throws Exception {
    ZMQ.Curve.KeyPair keyPair =  ZMQ.Curve.generateKeyPair();
    Assert.assertNotNull(keyPair);
}

Working code example:

@Test
public void noUnsatisfiedLinkError() throws Exception {
    Class.forName("org.zeromq.ZMQ");
    ZMQ.Curve.KeyPair keyPair =  ZMQ.Curve.generateKeyPair();
    Assert.assertNotNull(keyPair);
}
jcoeltjen commented 7 years ago

This is a duplicate of #403 and may be closed.