phxql / argon2-jvm

Argon2 Binding for the JVM
GNU Lesser General Public License v3.0
331 stars 33 forks source link

NoSuchMethodErrors for com.sun.jna.Native.load #72

Closed nrktkt closed 3 years ago

nrktkt commented 4 years ago

I'm starting to see errors locally and on CI like

java.lang.NoSuchMethodError: com.sun.jna.Native.load(Ljava/lang/String;Ljava/lang/Class;)Lcom/sun/jna/Library;
  at de.mkammerer.argon2.jna.Argon2Library.<clinit>(Argon2Library.java:13)
  at de.mkammerer.argon2.BaseArgon2.hashBytes(BaseArgon2.java:287)
  at de.mkammerer.argon2.BaseArgon2.hashBytes(BaseArgon2.java:279)
  at de.mkammerer.argon2.BaseArgon2.hash(BaseArgon2.java:61)

Here's a build with the failure https://travis-ci.com/github/lightform-oss/2Auth/builds/165341286 library version 2.7 running openjdk version "11.0.2" 2019-01-15 OpenJDK Runtime Environment 18.9 (build 11.0.2+9) OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)

Clearly the build and runtime environments are not on compatible versions of JNA, but it feels like this happened rather suddenly. Any ideas?

phxql commented 4 years ago

The newest version updated JNA (see https://github.com/phxql/argon2-jvm/blob/master/CHANGELOG.md#27---2020-04-15). Can you run a mvn dependency:tree or gradle dependencies and find out the JNA version in your project?

nrktkt commented 4 years ago

The only JNA shown by mill show _.ivyDepsTree is

├─ de.mkammerer:argon2-jvm:2.7
│  └─ net.java.dev.jna:jna:5.5.0

I'm not super savvy on how JNA works. Is that dependency all that is required, or is there a matching JNA (or JNI) implementation provided by the JVM or something whose version I could check as well?

phxql commented 4 years ago

That looks like the correct JNA version. JNA is all you need. I have no idea how mill works, it seems like the classpath is botched. Have you tried older versions of argon2-jvm?

nrktkt commented 4 years ago

2.6 does seem to work fine

@QuestofIranon if you're seeing a similar error, can you chime in with your build environment?

jippeholwerda commented 3 years ago

I have exactly the same problem. In my case, argon2-jvm is used when running Flyway (https://github.com/flyway/flyway) database migrations via the command line. I noticed Flyway uses version JNA version 4.5.2. Both versions are probably on the classpath and incompatible?

argon2-jvm versino 2.6 was working properly.

phxql commented 3 years ago

You can't have both JNA 4.5.2 and JNA 5.5.0 on the classpath - Java can only have on version on the classpath. If you run mvn dependency:tree and look for jna you see the exact version on the classpath.

You have two options: use a newer flyway which uses a modern version of JNA, or force maven to use the JNA argon2-jvm requires via a <dependencyManagement> entry in the POM and hope that Flyway works with the newer version.

If this isn't a possibility for you, then just use argon2-jvm in 2.6 - no harm doing that. The changes in 2.7 are not security-relevant.

jippeholwerda commented 3 years ago

In my project's dependencies there is only JNA 5.5.0 (from argon2-jvm). I don't have control over Flyway's dependencies, so I'll just stick with argon2-jvm 2.6.