How to resolve IncompatibleClassChangeError interface not implemented

Ahsan Iqbal picture Ahsan Iqbal · Sep 25, 2015 · Viewed 8k times · Source

I know the question is asked already but somehow I can't find any convincing solution after googling for about an hour.

I am using apache-jena to load RDF model from a url. And I am getting IncompatibleClassChangeError with following message

Class org.apache.http.impl.client.SystemDefaultHttpClient does not implement the requested interface org.apache.http.client.HttpClient

Can someone give some pointer how can I resolve this error.

Regards Ahsan

Answer

Pankaj Saboo picture Pankaj Saboo · Sep 25, 2015

This is thrown when an incompatible class change has occurred to some class definition. The definition of some class, on which the currently executing method depends, has since changed. It is normally thrown when a non-final field of a base class becomes static, or when the base class turns into an interface (and vice versa), etc. The IncompatibleClassChangeError extends the LinkageError, which is related to problems rising from a base class that changes after the compilation of a child class.

Please read more here

http://examples.javacodegeeks.com/java-basics/exceptions/java-lang-incompatibleclasschangeerror-how-to-resolve-incompatible-class-change-error/

http://howtodoinjava.com/2013/05/25/solved-java-lang-incompatibleclasschangeerror-implementing-class/

Your newly packaged library is not backward binary compatible (BC) with old version. For this reason some of the library clients that are not recompiled may throw the exception.

This is a complete list of changes in Java library API that may cause clients built with an old version of the library to throw java.lang.IncompatibleClassChangeError if they run on a new one (i.e. breaking BC):

Non-final field become static, Non-constant field become non-static, Class become interface, Interface become class, if you add a new field to class/interface (or add new super-class/super-interface) then a static field from a super-interface of a client class C may hide an added field (with the same name) inherited from the super-class of C (very rare case). Note: There are many other exceptions caused by other incompatible changes: NoSuchFieldError, NoSuchMethodError, IllegalAccessError, InstantiationError, VerifyError, NoClassDefFoundError and AbstractMethodError.

The better paper about BC is "Evolving Java-based APIs 2: Achieving API Binary Compatibility" written by Jim des Rivières.

There are also a lot of automatic tools to detect such changes:

japi-compliance-checker clirr japitools sigtest japi-checker Usage of japi-compliance-checker for your library (*.jar):

japi-compliance-checker OLD.jar NEW.jar Usage of clirr tool:

java -jar clirr-core-0.6-uber.jar -o OLD.jar -n NEW.jar