Quick revision
The short answer
NoSuchMethodError at run time means the class that was loaded is a different version from the one the code was compiled against, which almost always means two versions of the same library are present and the old one won. We find the jar the class came from with -Xlog:class+load=info or -verbose:class, or by logging the class's code source at startup, then look for the extra copy in the deployment: a stray jar in a lib folder, an application server's shared libraries, or a fat jar of another library carrying old Jackson classes. We fix it with dependency management, exclusions and Maven Enforcer rules.
What to remember
In this answer, we saw that NoSuchMethodError means the loaded class differs from the one we compiled against, usually because two versions of a library are present. We found the winning jar with class load logging or the class's code source, looked at the usual sources of the extra copy, fixed it with dependency management, exclusions and Enforcer rules, and saw that local and production differ because of how each launches the application.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
NoSuchMethodError at run time means the class that was loaded is a different version from the one the code was compiled against, which almost always means two versions of the same library are present and the old one won. We find the jar the class came from with -Xlog:class+load=info or -verbose:class, or by logging the class's code source at startup, then look for the extra copy in the deployment: a stray jar in a lib folder, an application server's shared libraries, or a fat jar of another library carrying old Jackson classes. We fix it with dependency management, exclusions and Maven Enforcer rules.
Why this question is asked
This bug is maddening because everything looks right: the build declares the correct Jackson version, the tests pass, the application runs perfectly on a laptop, and yet production throws an error saying a method does not exist. Interviewers like it because solving it requires understanding the difference between compile time and run time, how the class path decides which class wins, and how to see what the JVM actually loaded. In this answer, we will see what the error really means, find the jar the class came from, look at the usual sources of the extra copy, fix it, and explain why local and production differ.
1What NoSuchMethodError Really Means
When javac compiles a call, it records in the class file the exact class, method name and parameter types of the method being called. At run time, the JVM links that call the first time it runs, by looking up the method in whatever class with that name it actually loaded. If that class does not have the method, linking fails with NoSuchMethodError.
So the error does not mean our build is wrong. It means the class loaded at run time is not the class we compiled against. Usually some library, for example jackson-databind 2.17, was compiled against jackson-core 2.17 and calls a method added in that version, but at run time an older jackson-core, say 2.12, is earlier on the class path, so its JsonFactory class is loaded instead. Everything else in jackson-core 2.12 works, which is why the failure appears only on the code path that uses the new method.
2Finding the Jar the Class Came From
The fastest way to confirm the cause is to ask the JVM where it loaded the class from. Class loading logging prints one line per loaded class, with its source.
Notice that the path names the guilty jar directly. Here it is a file in /opt/app/lib, not the version our build declared. The code source can be null for classes from the JDK itself, which is why the snippet checks for it. In a Spring Boot fat jar, the location points to a nested jar inside BOOT-INF/lib; the exact URL format depends on the Boot version. We can also log the library's own version constant, such as com.fasterxml.jackson.core.json.PackageVersion.VERSION, to see the version string directly.
3Where the Extra Copy Usually Comes From
Once we know which jar won, we look at how it got there. The usual sources are few. An extra jar sits in a lib directory that a start script adds with a wildcard, perhaps left over from an older release or copied in by a Dockerfile. An application server, such as an older Tomcat or WebSphere setup, provides shared libraries that are loaded by a parent class loader and seen before the application's own. Or another dependency is a shaded fat jar that bundles its own copy of Jackson classes under the original package names, so the classes appear on the class path twice without any visible jackson-core dependency.
The last case is the hardest to spot, because the dependency tree looks clean. Listing the contents of suspicious jars, or searching all jars on the class path for the class file name, reveals it.
- Read the error: which class and method?the class that lacks the method is the suspect
- Log where that class was loaded from-Xlog:class+load or
getCodeSource() - Is it the version the build declares?YesCheck the caller's version insteadNoFind how the wrong jar got there
- Stray jar, server library or shaded copy?dependency tree, jar listings
- Fix: align versions, exclude, relocatethen add an Enforcer rule
5 steps in order. Play them, or step through them one at a time.
4Fixing It and Keeping It Fixed
The fix is to have exactly one version of the library, the right one. If two versions come in through dependencies, we manage the version centrally: in Maven with dependencyManagement, ideally importing the jackson-bom, and in Gradle with a platform. Spring Boot already manages Jackson's version for its starters, so overriding it with an explicit version in one module often causes the mismatch in the first place. If a dependency pulls in an unwanted copy, we exclude it. If the copy is a shaded jar, we ask the vendor for a relocated build or a thin jar, or relocate it ourselves with the shade plugin. If it is a stray file in a lib folder, we fix the image build.
Then we stop it from returning. The Maven Enforcer plugin's dependencyConvergence rule fails the build when two paths request different versions of the same artifact, and the banDuplicateClasses rule from the extra-enforcer-rules project fails it when two jars contain the same class, which also catches shaded copies. Gradle has equivalent options, such as failing on version conflicts.
5Why Local and Production Differ
The application worked locally because it was launched differently. The IDE builds its class path from the build tool's resolved dependencies, in its own order, and never sees the production lib folder or the application server's shared libraries. Production runs a packaged artifact, through a start script, a container image or a server, with whatever else that environment adds.
So the most reliable way to reproduce such errors is to run the exact artifact the way production runs it, for example the container image locally, and to make the packaged artifact the only thing that decides the class path, with no wildcard lib folders that collect leftovers.
6Follow-up questions
How does the module path change this kind of conflict?
On the module path, two modules with the same name cannot both be resolved, and two modules that contain the same package are rejected at startup with an error that a module reads the package from both, so the conflict is found when the JVM starts rather than when a method is first called. The class path silently picks the first jar, which is why such errors appear late and only on some code paths. Automatic modules made from plain jars follow these rules too.
Why is the error NoSuchMethodError and not a compile error?
Because compilation used the correct version. The compiler checked our code and Jackson's code against the jars in the build, which were consistent. The mismatch exists only in the run-time class path, which the compiler never saw.
Could NoClassDefFoundError or AbstractMethodError come from the same cause?
Yes. They are siblings: NoClassDefFoundError when a class the code needs is missing from the loaded version, AbstractMethodError when an interface gained a method that an old implementation lacks, and IncompatibleClassChangeError for other structural changes. All of them point to mixed versions on the class path.
7Conclusion
In this answer, we saw that NoSuchMethodError means the loaded class differs from the one we compiled against, usually because two versions of a library are present. We found the winning jar with class load logging or the class's code source, looked at the usual sources of the extra copy, fixed it with dependency management, exclusions and Enforcer rules, and saw that local and production differ because of how each launches the application.
Open with
NoSuchMethodError at run time means the class the JVM loaded is not the version our code was compiled against. The compiler recorded a call to a method that existed at build time, but at run time an older copy of the class was found first.
Then, if they want more
In practice that means two versions of the library, for example a new jackson-databind running with an old jackson-core. First I would prove which jar the class came from. I would run with -Xlog:class+load=info, or -verbose:class, and grep for the class, which prints the source jar, or log JsonFactory.class.getProtectionDomain().getCodeSource().getLocation() at startup.
Then I would look at how that jar got there: a stray jar in a lib directory added by a wildcard, an application server's shared libraries, or a shaded fat jar of another dependency that carries old Jackson classes under the original package. mvn dependency:tree with includes, or Gradle dependencyInsight, shows normal paths, and searching the jars for the class file finds shaded copies.
The fix is one managed version: Spring Boot's managed Jackson version or the Jackson BOM, exclusions, or a relocated shaded jar. To keep it fixed, I would add Maven Enforcer's dependencyConvergence and banDuplicateClasses rules. It worked locally because the IDE builds its own class path and never sees production's lib folder or server, so I reproduce with the real artifact.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "In production a service throws NoSuchMethodError on a Jackson method that exists in the...": https://scrivio-interview-library.netlify.app/java/jvm-architecture/e02afabfc5/