GetStream/stream-chat-java

JWT method signWith(java.security.Key, io.jsonwebtoken.SignatureAlgorithm) is not found at runtime despite including all dependencies

coderman2022 opened this issue · 3 comments

Describe the bug
When using the stream-chat-java library, this error occurs at runtime (not during compile), even though all JWT dependencies are included:

java.lang.AbstractMethodError: Receiver class io.jsonwebtoken.impl.DefaultJwtBuilder does not define or inherit an implementation of the resolved method 'abstract io.jsonwebtoken.JwtBuilder signWith(java.security.Key, io.jsonwebtoken.SignatureAlgorithm)' of interface io.jsonwebtoken.JwtBuilder

To Reproduce
include these dependencies in sbt:

      "io.jsonwebtoken" % "jjwt-api" % "0.11.2",
      "io.jsonwebtoken" % "jjwt-impl" % "0.11.2" % "runtime",
      "io.jsonwebtoken" % "jjwt-jackson" % "0.11.2" % "runtime",

These install instructions are according to https://github.com/jwtk/jjwt#install-jdk-maven

The runtime error occurs when calling methods in the library "io.getstream" % "stream-chat-java", which uses JWT.

Stack trace of the error starting in the GetStream library:

java.lang.AbstractMethodError: Receiver class io.jsonwebtoken.impl.DefaultJwtBuilder does not define or inherit an implementation of the resolved method 'abstract io.jsonwebtoken.JwtBuilder signWith(java.security.Key, io.jsonwebtoken.SignatureAlgorithm)' of interface io.jsonwebtoken.JwtBuilder.
	at io.getstream.chat.java.services.framework.DefaultClient.jwtToken(DefaultClient.java:153)
	at io.getstream.chat.java.services.framework.DefaultClient.lambda$new$0(DefaultClient.java:98)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
	at io.getstream.chat.java.services.framework.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:170)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
	at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:229)
	at okhttp3.RealCall.execute(RealCall.java:81)
	at retrofit2.OkHttpCall.execute(OkHttpCall.java:204)
	at io.getstream.chat.java.services.framework.StreamServiceHandler.handle(StreamServiceHandler.java:18)
	at io.getstream.chat.java.models.framework.StreamRequest.request(StreamRequest.java:24)

If I include the additional line in sbt (this dependency was not included above):

"io.jsonwebtoken" % "jjwt" % "0.9.1"

Then I get a different error:

java.lang.NoSuchMethodError: 'io.jsonwebtoken.JwtBuilder io.jsonwebtoken.JwtBuilder.signWith(java.security.Key, io.jsonwebtoken.SignatureAlgorithm)' at io.getstream.chat.java.services.framework.DefaultClient.jwtToken(DefaultClient.java:153) at io.getstream.chat.java.services.framework.DefaultClient.lambda$new$0(DefaultClient.java:98)

Expected behavior
Program should run successfully when calling JWT methods.

I found the problem. For anyone else using Java Play Framework, it is Java Play that includes the transitive dependency on com.typesafe.play:filters-helpers_2.12:2.8.11, which in turn brings in the JWT dependency on io.jsonwebtoken, which is not the implementation that GetStream depends on.

To fix the above error, io.jsonwebtoken needs to be excluded, not included as is described in the GetStream documentation. This is accomplished by putting excludeDependencies += "io.jsonwebtoken" % "jjwt" at the top level of build.sbt.

It should be available in runtime. If a framework brings it in a different level, of course it should be excluded there to be included in runtime.

Good to hear you were able to get it worked.

Why don't you want to include this dependency inside getstream library? Right now I have problems combining two different jwt dependencies. I need 0.9.1 in my project and you use 0.11.2