Forum Stats

  • 3,769,802 Users
  • 2,253,023 Discussions


Help! -- different class loader issue

843798 Member Posts: 24,864
From within and EJB I am trying to cast a serializable object, that was passed into this EJB, to its original type. The process ended with a ClassCastException, even though I have double checked that the object being casted is of the correct type and fully qualified package path. It turns out that the problem is caused by the involvment of 2 different class loaders -- The class loader that loads the object is not the same one that loads the EJB doing the casting. The thing that confuses me the most is that this program used to work fine without the exception when it was running in an older environment. Is this a VM issue? Do we have control over what class loader to use when load certain classes/objects? What's the fix to the problem?

Please help!

Thanks in advance.



  • 843798
    843798 Member Posts: 24,864
    A classloader must return the same class object reference for the same class name every time it is asked for it. Otherwise the system will believe there are two different classes with the same name and will throw a ClassCastException whenever you assign an object reference between them.

    So, the question is, why are the two class loaders loading the same class?
This discussion has been closed.