6 Replies Latest reply on May 27, 2015 2:20 PM by SANJAY GAUTAM

    ClassCastException when casting to same object.

    D P Apprentice

      I am adding object of DataSourceDT type to ArrayList<Object> and trying to retrieve it.

       

      I am getting following exception.

       

      java.lang.ClassCastException: com.myclass.report.DataSourceDT cannot be cast to com.myclass.report.DataSourceDT

          at org.apache.cocoon.www.reportadmin.xsp.ListDataSource_xsp.generate(ListDataSource_xsp.java:808)

          at org.apache.cocoon.generation.ServerPagesGenerator.generate(ServerPagesGenerator.java:228)

          at org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.processXMLPipeline(AbstractProcessingPipeline.java:578)

          at org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipeline.processXMLPipeline(AbstractCachingProcessingPipeline.java:183)

          at org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.process(AbstractProcessingPipeline.java:779)

          at org.apache.cocoon.components.source.impl.SitemapSource.toSAX(SitemapSource.java:412)

          at org.apache.cocoon.components.source.SourceUtil.toSAX(SourceUtil.java:100)

          at org.apache.cocoon.components.source.SourceUtil.parse(SourceUtil.java:320)

          at org.apache.cocoon.sitemap.ContentAggregator.generate(ContentAggregator.java:126)

       

      My application is deployed  in EAR which has WAR and JAR files.

       

      This code was working fine with JBoss AS 4.0.3 and JDK6.

      Currently I am using Wildfly 8.2.0 and JDK8

       

      Thanks,

        • 1. Re: ClassCastException when casting to same object.
          SANJAY GAUTAM Expert

          You have to find all the jars where you  have this class DataSourceDT and then have this class only load form one place. It goes with out saying that Class loading class comparison includes three attributes of Class  class name , class id  which is provided by class loader , Your Class  DataSourceDT Seems to be loaded by Different Class loaders and hence above error  is bound to happen .

           

          thanks

          Sanjay Gautam

          • 2. Re: ClassCastException when casting to same object.
            D P Apprentice

            Thanks Sanjay for reply,

             

            EAR file has WAR and JAR file. This class exist in both of them.
            Web layer use Cocoon (XSPs, XMAPs) framework, I tried to remove this file from WAR. Now it started throwing com.myclass.report package does not exist error.

             

            Thanks,

            • 3. Re: ClassCastException when casting to same object.
              SANJAY GAUTAM Expert

              I think you there is no direct answer but , I believe if your XSPs are using this class then probably it have had to be in the war so removing it from there might now help.  Secondly this ear , how are you deploying , I mean there is option to deploy ear in which all the ear level can access war and jar level stuff are you doing that class loading strategy ? described in this documentation  Class Loading in Widlfy  ear-subdeployments-isolated


              Secondly the framework can also create the issues as they may have different class loaders strategy , I faced the similar issue in the JBPMN , SOAP WebService Work Item Handler. which uses the CXF  apis to create runtime XML/Java objects . I had to write the work Item handler totally new as the out of the box didnt used the right method provided by CXF apis.

               

              Thanks

              Sanjay Gautam

              • 4. Re: ClassCastException when casting to same object.
                D P Apprentice

                I am not specifying any class loading strategy.

                 

                How to load the classes with one classloader only.

                 

                Thanks,

                Dhaval

                • 5. Re: ClassCastException when casting to same object.
                  Jay SenSharma Master

                  Dhaval,

                   

                     You need to make sure that you only have one JAR file that contains the class "com.myclass.report.DataSourceDT".    (inside your application or inside custom modules)

                  • 6. Re: ClassCastException when casting to same object.
                    SANJAY GAUTAM Expert

                    Many time it happens when with frameworks generating code at runtime and then instantiating the classes using their classloader instead of the one from one's application trails. but I can say that wildfly modular class loader still not so solid or there is not enough to the point documentations about its real functioning . I personally didnt have great fun migrating my applications to wildfly.  there are still lots of conflicts do arise.