We are using dozer mapping in our J2EE application running on IBM websphere7 to map two classes. We are using it as
mapper.map(classA, Class.forName(classB));
This is working always except very very occasionally, when it fails with a ClassCastException (Happened once in production in two years, once in 3 or 4 months in test region). When this exception occurs, we would continue getting it till we recycle the node. (Other nodes would be working fine at the time). On examining the dumps generated, we noticed the following.
All other parameters seems to be fine.
Our assumption is that, ClassCastException happens when the source class and destination class is loaded by different classloaders.
Could this be a correct assumption? If so, how can we be sure of it (we have heap dumps and thread dumps of the time).
What else can cause an issue like this?
Anything else that should be looked into?
Any possible solutions for this?
As answered by unique_ptr
this Could this be a correct assumption? yes very probable, you could try to ensure the class loader conext before like Thread.currentThread().setContextClassLoader(paramClassLoader); and reset it back after.
To set the correct classloader, either explicitly set dozer's classloader via org.dozer.util.DozerClassLoader and set classB.getClass().getClassLoader() or set the classLoader in the thread context with mapper.getClass().getClassLoader(). Don't forget to put back the original one or you'll get CNF exception with your application