Uploaded image for project: 'EJB 3.0'
  1. EJB 3.0
  2. EJBTHREE-1189

ClassCastException within EAR - Stateless Session Bean interface flattening hierarchy

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • AS 4.2.0 GA
    • None
    • None

    Description

      Project structure
      =============
      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 (stateless session 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?

      Attachments

        Activity

          People

            Unassigned Unassigned
            heizenberg_jira Ananda Debnath (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: