square / jna-gmp

A Java JNA wrapper around the GNU Multiple Precision Arithmetic Library.
Apache License 2.0
62 stars 24 forks source link

java.lang.NoClassDefFoundError exception #31

Open Koshak118 opened 5 years ago

Koshak118 commented 5 years ago

Hi

Thanks for this great wrapper, first of all

The issue I've been messing around in a last couple of days is the exception mentioned in the subject, which is thrown in runtime. The trivial things like playing dependencies definitions and their scopes in pom.xml did not help, the local maven repositories and paths seem to be OK. The stack is as the following:

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class ```
com.squareup.jnagmp.LibGmp
    at com.squareup.jnagmp.Gmp.<init>(Gmp.java:175)
    at com.squareup.jnagmp.Gmp.<init>(Gmp.java:33)
    at com.squareup.jnagmp.Gmp$1.initialValue(Gmp.java:133)
    at com.squareup.jnagmp.Gmp$1.initialValue(Gmp.java:131)
    at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:180)
    at java.lang.ThreadLocal.get(ThreadLocal.java:170)
    at com.squareup.jnagmp.Gmp.modPowInsecure(Gmp.java:95)

The relevant pom.xml section:

<dependencies>
        <dependency>
            <groupId>com.squareup.jnagmp</groupId>
            <artifactId>jnagmp</artifactId>
            <version>2.1.0</version>
        </dependency>
..........
        <dependency>
            <groupId>com.squareup.jnagmp</groupId>
            <artifactId>bouncycastle-rsa</artifactId>
            <version>2.1.0</version>
        </dependency>
</dependencies>

Any ideas?

Thanks

dragonsinth commented 5 years ago

@Koshak118 I think this exception generally means that the target class failed to initialize properly-- ie its static initializer(s) threw an exception. But I would have expected to see more information in the stack trace, or a separate exception trace detailing why LibGmp failed to load.

Koshak118 commented 5 years ago

Hi @dragonsinth

Thanks for the fast answer. The following is the more comprehensive stack trace with my own code wiped out (I am working under NDA and cannot disclose the exact functionality which uses your library). Generally the logic is trying to make a "multiply" operation in homomorphic encryption algorithm which includes "mod" operation as well

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class com.squareup.jnagmp.LibGmp
    at com.squareup.jnagmp.Gmp.<init>(Gmp.java:175)
    at com.squareup.jnagmp.Gmp.<init>(Gmp.java:33)
    at com.squareup.jnagmp.Gmp$1.initialValue(Gmp.java:133)
    at com.squareup.jnagmp.Gmp$1.initialValue(Gmp.java:131)
    at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:180)
    at java.lang.ThreadLocal.get(ThreadLocal.java:170)
    at com.squareup.jnagmp.Gmp.modPowInsecure(Gmp.java:95)
    at ********************************************************************
    at ********************************************************************
    at ********************************************************************
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:545)
    at java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
    at java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:438)
    at *******************************************************************************
dragonsinth commented 5 years ago

@Koshak118 are you on the latest version? Those line numbers make no sense based on the current source code I'm looking at.

Koshak118 commented 5 years ago

Hi @dragonsinth

Sorry for the delayed answer, was with a limited access to the internet for a couple of days

Upgrading the code to the latest version didn't fix a crash; what did fix it is trying to run the code on Mac rather than on Windows, so it looks like it was an environment setup issue

As far as I am concerned you can close the issue

Thanks for the assistance

dragonsinth commented 5 years ago

Ah, yes. We don't provide a pre-built binary libgmp for Windows. You'd need to build libgmp yourself.