2 Replies Latest reply on Mar 21, 2006 7:08 AM by hjones

    ClassCastException for serialized class but acces via intros

    hjones

      Hi, I have the following strange behaviour: I implemented a simple
      stateless session bean (EJB3.0) that returns a Vector of a custom class
      called 'Info', which contains a String field accessible via Info.getName().

      The method of the bean interface is as follows:

      public Vector getInfoVector();
      


      The Info class is serializable and everything works fine using a stand-alone
      Java client.

      But when I try to use this bean in a JSP file, the following problem occurs:

      I am able to invoke the session bean method (getInfoVector) and I get the Vector result.
      I can successfully do the following:

      Object obj = vecResult.get(0);
      out.println(obj.getClass().getName()+"<br/>");
      Object objRes = obj.getClass().getMethod("getName", new Class[]{}).invoke(obj, new Object[]{});
      


      The class name of line 2 is exactly the class of Info and the intrtospection
      call results the correct data, i.e., the serialization of the Info class worked correctly.

      But I *cannot* do this:

      Info info = (Info)vecResult.get(0);
      out.println("Info: " + info.getName());
      


      The first (casting) line throws the following exception:

      java.lang.ClassCastException: com.dcx.rt.iqminer.ejbs.dataprovider.params.DataSourceInfo
       at org.apache.jsp.DataSourcesOverview_jsp._jspService(org.apache.jsp.DataSourcesOverview_jsp:76)
       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      .....
      


      Anyone any idea?
      Thanks in advance!

      BTW: I am using JBoss 4.0.4RC1 and it does not seam to be an error
      resulting from not using generics. It will crash in the same way if I use Vector as return type.