Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Debugging stories: IncompatibleClassChangeError

DZone's Guide to

Debugging stories: IncompatibleClassChangeError

· Java Zone
Free Resource

Never build auth again! The Okta Developer Platform makes it simple to implement authentication, authorization, MFA and more in Java applications. Get started with the free API.

IncompatibleClassChangeError, very much like its cousin NoSuchMethodError, indicates that the class you depend on has changed since you’ve last compiled.

In my case, the jvm tells me that the method I’ve been calling has changed from static to non-static. That’s a decent enough explanation to start with. You could recompile, fix the compilation errors and should be good to go.

Or not.

I compiled my changes against the latest build of the library, libA, added libA to the classpath. No luck, the jvm says class org.foo.Test.getInstance method has changed from static to non-static. Er, it was static when I compiled?

Turns out someone had copied over the class org.foo.Test into libB, and changed the method to non-static. A transitive dependncy I had pulled in libB to my class path and here I have two incompatible definitions of the same class in my classpath. One of them gets pulled when I compile and the other when I run. (Someone has been a lazy bum!)

Tip: to find the jar containing a class,

find . -iname *.jar | while read JAR; do jar tvf $JAR | grep 'org.foo.Test' && echo $JARF ; done

Build and launch faster with Okta’s user management API. Register today for the free forever developer edition!

Topics:

Published at DZone with permission of Alosh Bennett, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}