jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes IncompatibleClassChangeError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "IncompatibleClassChangeError" Watch "IncompatibleClassChangeError" New topic
Author

IncompatibleClassChangeError

Jeremy Thornton
Ranch Hand

Joined: Feb 21, 2002
Posts: 91
I'm encountering a java.lang.IncompatibleClassChangeError when I try to run up some code that I'm working on.
I've got a class which happens to implement an interface in the javax.activation package

If I create an instance of my class like

then call an implemented method
[CODE]
myClass.getName();
[CODE]
no problem.
However, if I cast to the Interface
DataSource stillMyClass = (DataSource)myClass;
stillMyClass.getName();
an Exception is thrown
java.lang.IncompatibleClassChangeError
I'm a bit confused as to exactly what causes this. Presumably the jar files that I'm using at runtime are different to those used to compile the class and the build process is slighly complicated so this seems possible. I've attempted to check this though and I'm *fairly* sure this isn't the case.
Any ideas as to what could be happening or how to further trace which jar files etc are being used at runtime? (any suggestions welcome).
Cheers,
Jeremy
Vinod Chandana
Ranch Hand

Joined: Aug 26, 2003
Posts: 59
Hi Jeremy,
I don't think u need to type cast it. Just say
DataSource stillMyClass = myClass;
This should work.
Regards,
Vinod.
Originally posted by Jeremy Thornton:
I'm encountering a java.lang.IncompatibleClassChangeError when I try to run up some code that I'm working on.
I've got a class which happens to implement an interface in the javax.activation package

If I create an instance of my class like

then call an implemented method
[CODE]
myClass.getName();
[CODE]
no problem.
However, if I cast to the Interface
DataSource stillMyClass = (DataSource)myClass;
stillMyClass.getName();
an Exception is thrown
java.lang.IncompatibleClassChangeError
I'm a bit confused as to exactly what causes this. Presumably the jar files that I'm using at runtime are different to those used to compile the class and the build process is slighly complicated so this seems possible. I've attempted to check this though and I'm *fairly* sure this isn't the case.
Any ideas as to what could be happening or how to further trace which jar files etc are being used at runtime? (any suggestions welcome).
Cheers,
Jeremy
Jeremy Thornton
Ranch Hand

Joined: Feb 21, 2002
Posts: 91
Yup, agree.
It was doing exactly this that caused the problem to raise it's ugly head.
Just to confirm:

blows up.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

IncompatibleClassChangeError means, simply, that the class file the compiler used to represent some class is different enough from the one used at runtime to cause a problem. So what you need to do is look closely at the classpath used by your compiler and by your runtime system (depends on your environment and build system) for multiple versions of (probably) activation.jar. When you're sure everything is consistent, then recompile everything, and the problem should go away.
[ October 06, 2003: Message edited by: Ernest Friedman-Hill ]

[Jess in Action][AskingGoodQuestions]
Vinod Chandana
Ranch Hand

Joined: Aug 26, 2003
Posts: 59
Hi Jeremy,
Try myClass.getClass().getName(); The following code works for me. It could also be a problem with the paths.
Regards,
Vinod.

Originally posted by Jeremy Thornton:
Yup, agree.
It was doing exactly this that caused the problem to raise it's ugly head.
Just to confirm:

blows up.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[EFH]: When you're sure everything is consistent, then recompile everything, and the problem should go away.
I would add, delete all old class files, then recompile everything. You may have an out-of-date .class file that's not being recompiled because the compiler doesn't see a need.


"I'm not back." - Bill Harding, Twister
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34


I would add, delete all old class files, then recompile everything.

Indeed. This is implicit in my definition of recompile, but not necessarily anyone else's. Anyway, yeah, what Jim said. That's the whole point.
Jeremy Thornton
Ranch Hand

Joined: Feb 21, 2002
Posts: 91
I'm using ant to build into a clean directory.
I've got some further experiments to try before asking for further help (custom class loaders etc. involved).
Thanks for the comments so far.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34


I've got some further experiments to try before asking for further help (custom class loaders etc. involved).

Ahhhh. Note that the same class file loaded by two different class loaders will be incompatible classes. Normally this shouldn't happen if you're using the Java 2 class loader mechanism, but it's possible.
Jeremy Thornton
Ranch Hand

Joined: Feb 21, 2002
Posts: 91
That does indeed seem to be the problem.
There is a class loader involved that knows about encrypted class files and one which deals with all other files. The Interface was being loaded by the encryption class loaded and the implementing class was loaded by the standard class loader leading to some run-time oddities.
Yuck.
Thanks for the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IncompatibleClassChangeError
 
Similar Threads
Problem updating the JAR file
Assigning references problem
Switch datasources using spring?
code generation/bytecode modification
Teradata Datasource configuration on WAS V5