views:

3681

answers:

2

For some reason our java library that we package as a jar is throwing all of these java.lang.IncompatibleClassChangeError when we try to invoke methods from it. It seems to be seemingly random. What would cause this error?

+8  A: 

This means that you have made some incompatible binary changes to the library without recompiling the client code. Java Language Specification S13 details all of such changes, most prominantly, changing non-static non-private fields/methods as static or visa-versa.

Recompile the client code against the new library, and you should be good to go.

UPDATE: If you publishing a public library, you avoid making incompatible binary changes as much as possible, and preserving what's known as "binary backward compatibility". Updating dependency jars alone ideally shouldn't break the application or the build.

notnoop
For some reason the developers here are having a problem where recompiling the client code doesn't fix the issue exactly. For some reason if they edit the file where it occurs and recompile the error no longer occurs there, but more will randomly pop-up elsewhere in the project, where the library is referenced. I am curious what could possibly be casuing this.
Zombies
Is there any dynamically generated code?
Kristopher Ives
Have you tried to do a clean build (delete all the `*.class` files) and recompiling? Editing files have similar effect.
notnoop
No dynamically generated code.... unless you would consider a JSP to be such. We did try deleting the class files and this didn't seem to help. The wierd thing is that it just doesn't seem to happen for me but it happens for other developer.
Zombies
Can you ensure that when you do a clean build you are compiling against the same jars you run with?
notnoop
A: 

Thanks. This really helped me. I and the team was struggling over this since last couple of days. We didnt knew the root cause.

Thanks again.

Utkarsh Shah