Home โบ Java exceptions โบ NoSuchMethodError
NoSuchMethodError: causes and fixes
Code calls a method that existed at compile time but is missing from the version on the run-time classpath.
What it looks like
java.lang.NoSuchMethodError: 'void com.google.common.base.Preconditions.checkArgument(boolean, java.lang.String, java.lang.Object)'Extends IncompatibleClassChangeError in java.lang.
What it means
Your code compiled against one version of a library, and at run time a different version is on the classpath that lacks the method with that exact signature. It is the classic symptom of dependency version conflicts, the so-called jar hell: two libraries need different versions of a third, and the build tool picks one. The message includes the full method signature, which tells you which library and which method.
Common causes
- Two dependencies pull different versions of the same library and the older one wins.
- A BOM or parent POM pins a version that is older than a library expects.
- An old jar bundled inside a shaded or fat jar overriding the newer one.
- Mixing artifacts from different releases of one framework, for example Spring modules at different versions.
How to fix it
- Run
mvn dependency:tree -Dverboseorgradle dependencyInsight --dependency nameto see which versions compete. - Force a single version with dependencyManagement (Maven) or a constraint or resolutionStrategy (Gradle).
- Align framework modules by importing the framework BOM.
- Print where the class came from:
Foo.class.getProtectionDomain().getCodeSource().
Broken and fixed
// compiled against Guava 31, runtime has Guava 20
Preconditions.checkArgument(ok, "bad %s", value);<dependencyManagement>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.2.1-jre</version>
</dependency>
</dependencyManagement>๐ Unravel the failing code ๐ Unravel the fix
Debug it faster
Paste the whole stack trace into the stack trace beautifier to hide framework frames, jump to the root cause and find the first line of your own code. It runs in your browser, so the trace never leaves your machine.
Frequently asked questions
Is NoSuchMethodError a checked or unchecked exception?
NoSuchMethodError is an Error (it extends IncompatibleClassChangeError). Errors signal serious problems in the JVM or environment; applications normally should not catch them, and ordinary catch (Exception e) blocks will not.
Which package is NoSuchMethodError in?
It lives in java.lang, so the import is import java.lang.NoSuchMethodError; (java.lang needs no import).
What is the first thing to check when I see NoSuchMethodError?
Read the message and the first stack trace line in your own code. The usual causes are: Two dependencies pull different versions of the same library and the older one wins; and A BOM or parent POM pins a version that is older than a library expects.