Reputation: 11
I am using WebSphere application server. At a point I am getting an error that is:
com.savvion.sbm.dms.svo.Document incompatible with com.savvion.sbm.dms.svo.Document.
I have searched on net and found that error cause is same class load by different classloader in java.
How to prevent class loading with different classloader. or alternative solution.
Upvotes: 1
Views: 1319
Reputation: 66
Your problematic code probably looks something like this:
Document d = (Document)object;
Where "object" is an instance of the Document class loaded on a (custom?) class loader, while the Document class referenced in this class (i.e. in the declaration of "d", and in the cast) is loaded on the thread's context class loader.
So, as you mentioned, the VM sees these as two different classes, even if the bytecode is exactly the same:
Two classes are the same class (and therefore the same type) if they are loaded by the same class loader (§2.17.2) and they have the same fully qualified name (§2.7.5).
http://docs.oracle.com/javase/specs/jvms/se6/html/Concepts.doc.html#20389
The solution to your problem depends on how your particular application is constructed and deployed, and it might not be trivial. A first step is to look at where the two classes are being loaded from. The output produced by adding "-verbose:class" to your Java command line arguments should show you which JAR file the classes reside in.
Upvotes: 2