8 Replies Latest reply on Feb 19, 2008 6:07 PM by Ananda Debnath

    ClassCastException within an EAR deployment

    Ananda Debnath Newbie

       

      DVS3.ear/
       +-Util.jar (J2EE utility project)
       | +-dvs3.Changelist (java interface)
       |
       +-Core.jar/ (EJB Project)
       | +dvs3.code.session.ChangelistService (java interface that extends dvs3.Changelist)
       | +dvs3.code.session.ChangelistServiceBean (stlss sess bean that implements ChangelistService)
       |
       +-WebUI.war/
       | +dvs3.code.action.JSFBackingBean (a bbean that calls a session bean service via JNDI)
      

      I'm assuming the manifest files are defined correctly since both Core.jar and Util.jar are referenced in the WebUI.war manifest file and Util.jar is referenced in the Core.jar manifest file.

      In the backing bean, I have this piece of code:

      String jndi = "DVS3EAR/ChangelistServiceBean/local";
       Object service = new InitialContext().lookup(jndi);
       System.out.println(service instanceof ChangelistService) // prints true
       System.out.println(service instanceof Changelist) // prints false
       Changelist service = (Changelist) obj; // fails with a ClassCastException
      

      Why is this?

      At some level, isn't this violating a fundamental java principle? Since ChangelistService is a Changelist, why can't I cast the service object to be a Changelist, but can cast it to be of type ChangelistService?

      Is this some kind of weird (but legal) classloading?