question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Keys.keyPairFor(SignatureAlgorithm.<whatever>) throws Method threw 'java.lang.NoSuchMethodError' exception.

See original GitHub issue

I’m trying to generate a key pair on the fly in my tests:

// Both throw the same exception
Keys.keyPairFor(SignatureAlgorithm.ES256)
Keys.keyPairFor(SignatureAlgorithm.RS512)

And I get this exception:

java.lang.NoSuchMethodError: io.jsonwebtoken.lang.Classes.invokeStatic(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Class;[Ljava/lang/Object;)Ljava/lang/Object;

	at io.jsonwebtoken.security.Keys.keyPairFor(Keys.java:210)
	at tech.beshu.ror.acl.blocks.rules.impl.JwtAuthRuleTests.shouldAcceptTokenWithValidEllipticCurveSignature(JwtAuthRuleTests.java:120)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

I’m using the latest version:

  compile 'io.jsonwebtoken:jjwt-api:0.10.5'
    runtime 'io.jsonwebtoken:jjwt-impl:0.10.5',
            // Uncomment the next line if you want to use RSASSA-PSS (PS256, PS384, PS512) algorithms:
            'org.bouncycastle:bcprov-jdk15on:1.60',
            'io.jsonwebtoken:jjwt-jackson:0.10.5'

Not sure what I’m doing wrong, as this should work as per documentation, right?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
marcoderamacommented, Sep 11, 2019

I’m not sure if this explains the original issue but this might help others that ended up here for the same/similar problem as @Wouter8.

My package was configured to use jjwt-api 0.10.7. Unit tests ran fine but when the package was used in a larger project, I ran into the same issue with io.jsonwebtoken.lang.Classes.invokeStatic. After many frustrating hours we figured out that the problem was due to some other package bringing in jjwt-0.6.0. Both jjwt-api-0.10.x and jjwt-0.6.0 implement io.jsonwebtoken.lang.Classes but the latter doesn’t have the Classes.invokeStatic method. If jjwt-0.6.0 ends up earlier in your classpath, then its definitions shadow the ones in jjwt-api-0.10.x and you get the NoSuchMethod error.

Our tools (sbt) didn’t flag the conflict because it couldn’t know that jjwt and jjwt-api were “the same thing”.

1reaction
ChocolateOverflowcommented, Apr 14, 2021

I’ve figured out that I needed to remove the jjwt dependency and have just the 3 listed in #installation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

fix error java.lang.NoSuchMethodError: 'int io.jsonwebtoken ...
This API uses JWT tokens and I use io.jsonwebtoken to manage what I need to make it work. Everything is fine except when...
Read more >
How to Fix java.lang.NoSuchMethodError in Java - Rollbar
NoSuchMethodError is a runtime error in Java which occurs when a method is called that exists at compile-time, but does not exist at...
Read more >
How to Solve java.lang.NoSuchMethodError in Java?
NoSuchMethodError occurs when an application does not find a method at runtime. In most cases, we're able to catch this error at compile-time....
Read more >
Nifi throw error: java.lang.NoSuchMethodError: org... - 233474
Bryan Bende Hi Bryan, I am following this link to set up Nifi putHDFS to write to Azure Data Lake. Connecting - 233474....
Read more >
Java Exception Handling - NoSuchMethodError - Airbrake Blog
A close look at the Java NoSuchMethodError, with functional code samples showing how such errors might be thrown during runtime execution.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found