This discussion is archived
14 Replies Latest reply: Dec 19, 2010 11:58 PM by 818603 RSS

Class cast exception on ear creation

818603 Newbie
Currently Being Moderated
I have an application which works fine under my development mode. I deployed it in websphere and executed it. It works fine at that time.
But then, I used maven to build it (double checked the enviroments) and then deployed it in websphere and executed it. At this time it throws and exception.

ClassCastException : cannot cast to Integer from [java.lang.Object

This is strange because I get no exception when I compile it, create ear from my IBM RAD IDE and then deploy and run it.
But I get it when the ear is build in Sun's JVM using Maven and then deployed it in Websphere (IBM JVM) and run it.

What might be the reason?
  • 1. Re: Class cast exception on ear creation
    EJP Guru
    Currently Being Moderated
    Post the stack trace.
  • 2. Re: Class cast exception on ear creation
    818603 Newbie
    Currently Being Moderated
    The error is a simple class cast exception like we see any other day

    just says ClassCastException : Cannot cast java.lang.Integer to [java.lang.Object


    sorry for not being able to post the complete stack trace
  • 3. Re: Class cast exception on ear creation
    787175 Newbie
    Currently Being Moderated
    If I remember rightly the '[Object' means that its an array of objects...Therefore not an Integer?

    -Fred                                                                                                                                                                                                                       
  • 4. Re: Class cast exception on ear creation
    818603 Newbie
    Currently Being Moderated
    Yes I understand that it is an error on conversion from Integer to Object array.

    But this should not have been the problem, The code is a successfully running, even in the production environment.
    The only change we have introduced is that previously the EAR was built using IBM's RAD by exporting the project as ear, but now we use MAVEN to build the ear.

    This problem is in advanced for loop and once I change the for loop to an iterator based approach, it works fine.
    But it used to work fine earlier when MAVEN was not used.

    The code snippet is:
              List<Object[]> objArr = session.createQuery(
                             FETCH_HQL_FOR_FETCHING_INTEGER_TYPE_USER_ID).list();
                   if (!objArr.isEmpty() && objArr.size() > 0) {
                        for (Object obj : objArr) {             //we get error here
                             usrId = ((Integer) obj).intValue();
                        }
                   }

    This should in no way cause the exception, with the amount work I have done in java.

    The exception is:
    java.lang.ClassCastException: java.lang.Integer incompatible with [Ljava.lang.Object;
         at pkg.CommonDAOImpl.getUsrId(CommonDAOImpl.java:900)
         at pkg.UserAuthenticationServiceImpl.loginUser(UserAuthenticationServiceImpl.java:91)
         at pkg.UserAuthenticationSAO.loginUser(UserAuthenticationSAO.java:75)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
         at java.lang.reflect.Method.invoke(Method.java:599)
         at flex.messaging.services.remoting.adapters.JavaAdapter.invoke(JavaAdapter.java:421)
         at flex.messaging.services.RemotingService.serviceMessage(RemotingService.java:183)
         at flex.messaging.MessageBroker.routeMessageToService(MessageBroker.java:1503)
         at flex.messaging.endpoints.AbstractEndpoint.serviceMessage(AbstractEndpoint.java:884)
         at flex.messaging.endpoints.AbstractEndpoint$$FastClassByCGLIB$$1a3ef066.invoke(<generated>)
         at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
         at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
         at org.springframework.flex.core.MessageInterceptionAdvice.invoke(MessageInterceptionAdvice.java:59)
         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
         at org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.invoke(ThrowsAdviceInterceptor.java:126)
         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
         at org.springframework.aop.framework.Cglib2AopProxy$FixedChainStaticTargetInterceptor.intercept(Cglib2AopProxy.java:582)
         at flex.messaging.endpoints.AMFEndpoint$$EnhancerByCGLIB$$110976b5.serviceMessage(<generated>)
         at flex.messaging.endpoints.amf.MessageBrokerFilter.invoke(MessageBrokerFilter.java:121)
         at flex.messaging.endpoints.amf.LegacyFilter.invoke(LegacyFilter.java:158)
         at flex.messaging.endpoints.amf.SessionFilter.invoke(SessionFilter.java:44)
         at flex.messaging.endpoints.amf.BatchProcessFilter.invoke(BatchProcessFilter.java:67)
         at flex.messaging.endpoints.amf.SerializationFilter.invoke(SerializationFilter.java:146)
         at flex.messaging.endpoints.BaseHTTPEndpoint.service(BaseHTTPEndpoint.java:278)
         at flex.messaging.endpoints.AMFEndpoint$$EnhancerByCGLIB$$110976b5.service(<generated>)
         at org.springframework.flex.servlet.MessageBrokerHandlerAdapter.handle(MessageBrokerHandlerAdapter.java:101)
         at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
         at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
         at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
         at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
         at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1449)
         at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1384)
         at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131)
         at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
         at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
         at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
         at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
         at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
         at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
         at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
         at org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105)
         at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
         at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
         at org.springframework.security.ui.rememberme.RememberMeProcessingFilter.doFilterHttp(RememberMeProcessingFilter.java:109)
         at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
         at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
         at org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
         at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
         at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
         at org.springframework.security.ui.basicauth.BasicProcessingFilter.doFilterHttp(BasicProcessingFilter.java:174)
         at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
         at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
         at org.springframework.security.ui.webapp.DefaultLoginPageGeneratingFilter.doFilterHttp(DefaultLoginPageGeneratingFilter.java:86)
         at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
         at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
         at org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:277)
         at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
         at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
         at org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:89)
         at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
         at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
         at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
         at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
         at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
         at org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:175)
         at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
         at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
         at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
         at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
         at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
         at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:852)
         at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:785)
         at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:443)
         at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:175)
         at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91)
         at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:859)
         at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1557)
         at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:173)
         at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
         at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
         at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
         at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
         at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
         at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
         at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
         at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:202)
         at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:766)
         at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:896)
         at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1527)

    Edited by: Mridul on Dec 14, 2010 10:14 PM
  • 5. Re: Class cast exception on ear creation
    EJP Guru
    Currently Being Moderated
    But I get it when the ear is build in Sun's JVM using Maven and then deployed it in Websphere (IBM JVM) and run it.
    Why are you doing that? It's very poor practice. You should use the same JDK for development and production. Then if you have problems like this they will arise in development where you can debug them.
  • 6. Re: Class cast exception on ear creation
    818603 Newbie
    Currently Being Moderated
    For any product like ours, The decision lies in the client where he/she might want to use it, in which application server, and which vendor's jdk is to be used. We can only specify the version of the JDK.
    So, we have to make it executable in multiple type of JDK.
    Also, the only significant difference between JDK's (Sun ad IBM) is how they treat RMIC. It has been shown empirically that Sun and IBM JDK's are identical except for the RMIC and Orb components.
  • 7. Re: Class cast exception on ear creation
    818603 Newbie
    Currently Being Moderated
    Now I changed by MAVEN,s build JDK to IBM's. And still it gives me the same problem.
    Now it feels real real strange. The only difference is that one ear is built by RAD which runs
    and the MAVEN one does not
  • 8. Re: Class cast exception on ear creation
    EJP Guru
    Currently Being Moderated
    For any product like ours, The decision lies in the client where he/she might want to use it, in which application server, and which vendor's jdk is to be used. We can only specify the version of the JDK.
    Of course it's the client's decision. So you have to support all the JDKs that your clients use. So you have to use them all at development time. So that you don't get surprises like this at deployment time or execution time.
    So, we have to make it executable in multiple type of JDK.
    See above.
    Also, the only significant difference between JDK's (Sun ad IBM) is how they treat RMIC. It has been shown empirically that Sun and IBM JDK's are identical except for the RMIC and Orb components.
    I don't know where you got that factoid from but it is most certainly not correct. I can name at least two other differences off the top of my head. And factoids like this don't absolve you of the responsibility to test in the target environment. It's become a cliche: 'Java: write once, test everywhere'.
  • 9. Re: Class cast exception on ear creation
    EJP Guru
    Currently Being Moderated
    The only difference is that one ear is built by RAD which runs and the MAVEN one does not
    So you have to investigate that difference.
  • 10. Re: Class cast exception on ear creation
    818603 Newbie
    Currently Being Moderated
    comparisions are complete and have synchronized both of them, but still get the same error while executing it
  • 11. Re: Class cast exception on ear creation
    787175 Newbie
    Currently Being Moderated
    so orig code is:
    List< Object[] > objArr = session.createQuery(
    FETCH_HQL_FOR_FETCHING_INTEGER_TYPE_USER_ID).list();
    if (!objArr.isEmpty() && objArr.size() > 0) {
    for (Object obj : objArr) { //we get error here
    usrId = ((Integer) obj).intValue();

    removing and renaming some stuff make things clear I believe.

    List<Object[]> objArrList = callQuery.list();
    for (Object objARRAY : objArrList) {
    ...Integer[] iarray (Integer[]) objARRAY;
    ... for (Integer i: iarray)
    .......usrId = i.intValue();
  • 12. Re: Class cast exception on ear creation
    tschodt Pro
    Currently Being Moderated
    Mridul wrote:
    The exception is:
    java.lang.ClassCastException: java.lang.Integer incompatible with [Ljava.lang.Object;
    Yes I understand that it is an error on conversion from Integer to Object array.
    The other way around; from Object array to Integer.
    But this should not have been the problem, The code is a successfully running, even in the production environment.
    The only change we have introduced is that previously the EAR was built using IBM's RAD by exporting the project as ear, but now we use MAVEN to build the ear.

    This problem is in advanced for loop and once I change the for loop to an iterator based approach, it works fine.
    That cannot explain it. There must be some other difference.
    Show us your implementation of an iterator based approach.
  • 13. Re: Class cast exception on ear creation
    818603 Newbie
    Currently Being Moderated
    @Fred : Actually the code is written with incorrect use of Generics.
    it should not have been List<Objec[]> but just List<Object>

    But since the compilation is fine, it should not be any problem at runtime. Because generics is only for compile time and the generics information is removed during compilation and hence has no effect on runtime.
  • 14. Re: Class cast exception on ear creation
    818603 Newbie
    Currently Being Moderated
    @tschodt:
    here is the iterator based work:

    List objList = session.createQuery(     HQL_TO_FETCH_USR_ID_BY_USER_ID + userId + "'").list();
                   
    Iterator iter = objList.iterator();
    while (iter.hasNext()) {
         Object obj = iter.next();
         usrId = (Integer)obj;
    }

    This works fine.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points