1 2 Previous Next 21 Replies Latest reply on Dec 28, 2006 8:22 AM by msqrt84

    ClassCastException problem when doing hot redeploy

    wchao

      Whether I use packed EAR files or unpacked directories, I always seem to get ClassCastException problems. It happens when I change even the most trivial things, but the common pattern seems to be that PortableRemoteObject.narrow triggers the problem. I get the following error:

      2002-04-24 01:11:57,973 ERROR [org.jboss.web.localhost.Engine] ApplicationDispat
      cher[/rmjobs] Servlet.service() for servlet jsp threw exception
      java.lang.ClassCastException
      at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Porta
      bleRemoteObject.java:293)
      at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
      at com.caraveltech.rmjobs.Util.getUser(Util.java:100)
      at com.caraveltech.rmjobs.Util.getUserValueObject(Util.java:187)
      at org.apache.jsp.index$jsp._jspService(index$jsp.java:73)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspSer
      vlet.java:202)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
      82)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDisp
      atcher.java:683)
      at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationD
      ispatcher.java:574)
      at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDis
      patcher.java:497)

      Does anyone know why this happens and how I can resolve the problem so I can use hot redeploy?

        • 1. Re: ClassCastException problem when doing hot redeploy

          http://main.jboss.org/forums/thread.jsp?forum=66&thread=13406

          I think the above fixes the problem. I was going
          to test for myself last weekend, but I didn't get time.

          Regards,
          Adrian

          • 2. Re: ClassCastException problem when doing hot redeploy
            wchao

            I want to try the patch that Scott made. How do I check out the source code that went into RC1? I tried the latest CVS but it is giving me problems with connection managers and PostgreSQL.

            • 3. Re: ClassCastException problem when doing hot redeploy
              wchao

              I got the RC1 files with the following command:

              cvs -z3 -d:pserver:anonymous@cvs.jboss.sourceforge.net:/cvsroot/jboss co -r JBoss_3_0_0_RC1 jboss-all

              Then I copied the new MarshalledValuePair.java and NamingContext.java files into jboss-all/naming/src/main/org/jnp/interfaces/. I recompiled successfully.

              However, when I go to test things, I'm still getting the ClassCastException when I use PortableRemoteObject.narrow():

              2002-04-24 11:23:49,154 ERROR [org.jboss.web.localhost.Engine] ApplicationDispat
              cher[/rmjobs] Servlet.service() for servlet jsp threw exception
              java.lang.ClassCastException
              at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Porta
              bleRemoteObject.java:293)
              at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
              at com.caraveltech.rmjobs.Util.getUser(Util.java:100)
              at com.caraveltech.rmjobs.Util.getUserValueObject(Util.java:187)
              at org.apache.jsp.index$jsp._jspService(index$jsp.java:73)
              at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
              at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspSer
              vlet.java:202)
              at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
              82)
              at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
              at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDisp
              atcher.java:683)
              at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationD
              ispatcher.java:574)
              at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDis
              patcher.java:497)
              at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary
              .java:819)
              at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.jav
              a:391)
              at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(Inser
              tTag.java:757)
              at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:369)
              at org.apache.jsp.rootLayout$jsp._jspService(rootLayout$jsp.java:279)
              at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
              at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspSer
              vlet.java:202)
              at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
              82)
              at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
              at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDisp
              atcher.java:683)
              at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationD
              ispatcher.java:431)
              at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDis
              patcher.java:355)
              at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestP
              rocessor.java:181)
              at org.apache.struts.action.RequestProcessor.processForward(RequestProce
              ssor.java:548)
              at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
              va:250)
              at org.apache.struts.action.ActionServlet.process(ActionServlet.java:110
              9)
              at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:452)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
              icationFilterChain.java:247)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
              ilterChain.java:193)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
              alve.java:243)
              at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
              .java:566)
              at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
              a:472)
              at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
              alve.java:190)
              at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
              .java:566)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
              torBase.java:528)
              at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
              .java:564)
              at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve
              .java:246)
              at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
              .java:564)
              at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
              a:472)
              at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
              at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:
              2343)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
              ava:180)
              at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
              .java:566)
              at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatche
              rValve.java:170)
              at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
              .java:564)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
              ava:170)
              at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
              .java:564)
              at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
              468)
              at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
              .java:564)
              at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
              a:472)
              at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
              ve.java:174)
              at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
              .java:566)
              at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
              a:472)
              at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
              at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcesso
              r.java:1012)
              at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.ja
              va:1107)
              at java.lang.Thread.run(Thread.java:536)

              Any clues why?

              • 4. Re: ClassCastException problem when doing hot redeploy

                I'd better test this for myself.

                Have you compared your packaging with the testsuite?

                Regards,
                Adrian

                • 5. Re: ClassCastException problem when doing hot redeploy

                  I've tried this with both Tomcat and Jetty using
                  the 3.0 branch from last weekend.

                  My test is jbosstest-web.ear from the testsuite.

                  Both work after a redeploy of the ear.

                  Regards,
                  Adrian

                  • 6. Re: ClassCastException problem when doing hot redeploy

                    But then looking at the source, none of them
                    narrow the object.

                    Regards,
                    Adrian

                    • 7. Re: ClassCastException problem when doing hot redeploy
                      wchao

                      I remember trying back in March with JBoss 3.0.0beta from Feb. 22, 2002. It worked when I didn't use PortableRemoteObject.narrow(). When I just did a regular cast without the narrow, it worked with the Feb. 22, 2002 beta. For some reason the narrow method causes problems and has been causing problems since the introduction of 3.0. It worked fine with JBoss 2.4.4.

                      • 8. Re: ClassCastException problem when doing hot redeploy
                        rboston

                        I've also just tested this with the latest patch and it still throws ClassCastException.
                        I've also tried it with a normal cast with no luck.

                        I posted this problem over a month back with no luck either.

                        This becomes most obvious when using ejb-refs.

                        • 9. Re: ClassCastException problem when doing hot redeploy
                          rboston

                          Has anyone gotten resolution with this issue?
                          I tried what was described below by using the latest code base and the problem continues.

                          So, do ejb-refs and hot deployment work for anybody out there? This is such a common thing, someone must have it working !!!

                          Thanks

                          • 10. Re: ClassCastException problem when doing hot redeploy

                            It seems to me that this problem still remains in jboss-3.0.1_tomcat-4.0.4. I have looked into the matter of ClassLoaders after hot redeploy. I use the following code to look-up a local home interface from a servlet:

                            --- code begin ---
                            logger.debug("SomeEJBHome was loaded by: " +
                               SomeEJBHome.class.getClassLoader().toString());
                            InitialContext ic = new InitialContext();
                            Context ejbCtx = (Context) ic.lookup("java:comp/env/ejb");
                            Object o = ejbCtx.lookup(ejbRefName);
                            Class[] intfs = o.getClass().getInterfaces();
                            logger.debug("intf : " + intfs[0].toString() + " was
                               loaded by: " + intfs[0].getClassLoader().toString());
                            home = (SomeEJBHome)o;
                            --- code end ---

                            This code works when the JBoss-Tomcat process is 'fresh' but fails with 'ClassCastException: proxy##' after first hot redeploy. As I understand it a ClassCastException comes either because a class has changed or because it is loaded by a different ClassLoader. I log the name of the ClassLoader of my SomeEJBHome interface, and the ClassLoader of the SomeEJBHome interface that the proxy returned from look-up implements:

                            Log before hot redeploy:
                            12:41:30,866 DEBUG [SomeEJBFactory] SomeEJBHome was
                               loaded by:    org.jboss.mx.loading.UnifiedClassLoader@2b9f14{    url=file:...
                            12:41:31,067 DEBUG [SomeEJBFactory] intf : interface    SomeEJBHome was loaded by:    org.jboss.mx.loading.UnifiedClassLoader@2b9f14{    url=file:...

                            Log after hot redeploy:
                            12:42:37,142 DEBUG [SomeEJBFactory] SomeEJBHome was    loaded by: org.jboss.mx.loading.UnifiedClassLoader@c0d0a8   { url=file:...
                            12:42:37,212 DEBUG [SomeEJBFactory] intf : interface SomeEJBHome was loaded by:    org.jboss.mx.loading.UnifiedClassLoader@2b9f14{    url=file:...

                            First I notice that the ClassLoader-object is new after hot redeploy. BUT the proxy that is returned from the lookup is not re-loaded! This means that the proxy implements the interface as loaded by the previous ClassLoader, while I try to cast it to an interface loaded by the new ClassLoader.

                            Do I have a valid point? Is there a work-around? Is there an alternative way of looking up the local home interface?
                            Is this a bug in JBoss? If so, will it be fixed? (I'm afraid that I am not into the procedures of bug-reporting in JBoss. If this should be reported, perhaps someone could point me in the right direction.)

                            • 11. Re: ClassCastException problem when doing hot redeploy
                              l.g.

                              And jboss-3.0.2 too... :(

                              • 12. Re: ClassCastException problem when doing hot redeploy

                                I see that I left out something in the log-prints above: The files that the UnifiedClassLoaders read from. The new loader reads from the .jar-file contained in the latest .ear file that was deployed. The old loader on the other hand, the one that was created just after the latest restart of the server, reads from the .ear that was first deployed. In other words: On my setup JBoss keeps the whole history of .ear-files since its latest restart (one for each hot redeploy) and also keeps the a UnifiedClassLoader that loads classes from these files. (The EJB of my example is a stateless session bean.)

                                Is there something I can do to avoid this? Can I tell a running JBoss server to throw away the old files, or set it up to throw away the previous .ear file at hot redeploy?

                                (I have tried to delete my previous .ear file before copying the new one into the deploy-catalog, without success. The tmp-files are still kept.)

                                • 13. Re: ClassCastException problem when doing hot redeploy

                                  I'm pretty sure this thread relates to the bug report no 562972 in sourceforge:
                                  http://sourceforge.net/tracker/index.php?func=detail&aid=562972&group_id=22866&atid=376685

                                  • 14. Re: ClassCastException problem when doing hot redeploy
                                    sandnettie

                                    I am experiencing this hot deploy issue, however, after reading through this thread, i think i'm a little confused as to where the problem may be. So is this a problem with the way i'm building my ear, or a true problem with JBoss? I'd be happy to supply anything i need to help with this.....

                                    Any help here would be greatly appreciated....
                                    Thanks!

                                    1 2 Previous Next