IllegalStateException: getAttribute: Session already invalidated

the_mario picture the_mario · Jan 28, 2011 · Viewed 15k times · Source

I have a problem with my first JSF/IceFaces (version 1.8.2) application running on JBoss 5.1.0.

I recieve an exception after a while, telling me about session problems. This is weird, because i do not use sessions in my code at all. The following logs show that none of my backing beans can be instantiated because of this error (from JBoss):

com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: bean.Abgrenzungsreise.
    at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:191)
    at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:106)
    at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:368)
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:222)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
    at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
    at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:107)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
    at javax.faces.component.UISelectItems.getValue(UISelectItems.java:141)
    at com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.getSelectItems(MenuRenderer.java:637)
    at com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.countSelectOptionsRecursive(MenuRenderer.java:448)
    at com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.renderSelect(MenuRenderer.java:377)
    at com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:119)
    at com.icesoft.faces.component.ext.renderkit.MenuRenderer.encodeEnd(MenuRenderer.java:51)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
    at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:370)
    at com.icesoft.faces.renderkit.dom_html_basic.GridRenderer.encodeChildren(GridRenderer.java:208)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
    at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:358)
    at com.icesoft.faces.renderkit.dom_html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:96)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
    at com.icesoft.faces.component.util.CustomComponentUtils.renderChild(CustomComponentUtils.java:339)
    at com.icesoft.faces.component.paneltabset.PanelTabSetRenderer.writeTabCell(PanelTabSetRenderer.java:977)
    at com.icesoft.faces.component.paneltabset.PanelTabSetRenderer.encodeEnd(PanelTabSetRenderer.java:423)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
    at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:503)
    at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:497)
    at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:497)
    at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:497)
    at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:497)
    at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:456)
    at com.icesoft.faces.application.D2DViewHandler.renderView(D2DViewHandler.java:159)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:19)
    at com.icesoft.faces.context.View$2$1.respond(View.java:48)
    at com.icesoft.faces.webapp.http.servlet.ServletRequestResponse.respondWith(ServletRequestResponse.java:201)
    at com.icesoft.faces.context.View$2.serve(View.java:77)
    at com.icesoft.faces.context.View.servePage(View.java:149)
    at com.icesoft.faces.webapp.http.core.SingleViewServer.service(SingleViewServer.java:52)
    at com.icesoft.faces.webapp.http.common.ServerProxy.service(ServerProxy.java:11)
    at com.icesoft.faces.webapp.http.servlet.MainSessionBoundServlet$4.service(MainSessionBoundServlet.java:149)
    at com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer.service(PathDispatcherServer.java:24)
    at com.icesoft.faces.webapp.http.servlet.BasicAdaptingServlet.service(BasicAdaptingServlet.java:16)
    at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23)
    at com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:53)
    at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23)
    at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:131)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:444)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
    at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:696)
    at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:667)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:58)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:662)
Caused by: com.icesoft.faces.webapp.http.core.SessionExpiredException: User session has expired or it was invalidated.
    at com.icesoft.faces.webapp.http.servlet.ProxyHttpSession.getAttribute(ProxyHttpSession.java:77)
    at com.icesoft.faces.webapp.http.servlet.ServletSessionAttributeMap.getAttribute(ServletSessionAttributeMap.java:16)
    at com.icesoft.faces.context.AbstractAttributeMap.containsKey(AbstractAttributeMap.java:85)
    at com.sun.faces.mgbean.BeanManager.isBeanInScope(BeanManager.java:177)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:82)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
    at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
    at bean.Abgrenzungsreise.(Abgrenzungsreise.java:39)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)
    at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:186)
    ... 86 more 
Caused by: java.lang.IllegalStateException: getAttribute: Session already invalidated at org.apache.catalina.session.StandardSession.getAttribute(StandardSession.java:1032) at org.apache.catalina.session.StandardSessionFacade.getAttribute(StandardSessionFacade.java:110) at com.icesoft.faces.webapp.http.servlet.ProxyHttpSession.getAttribute(ProxyHttpSession.java:75) ... 100 more 2011-01-28 08:05:54,326 ERROR [com.icesoft.faces.context.View] (http-0.0.0.0-8080-3) Problem encountered during View.servePage com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: bean.Abgrenzungsreise. at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:191) at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:106) at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:368) at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:222) at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86) at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54) at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72) at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61) at org.apache.el.parser.AstValue.getValue(AstValue.java:107) at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186) at javax.faces.component.UISelectItems.getValue(UISelectItems.java:141) at com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.getSelectItems(MenuRenderer.java:637) at com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.countSelectOptionsRecursive(MenuRenderer.java:448) at com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.renderSelect(MenuRenderer.java:377) at com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:119) at com.icesoft.faces.component.ext.renderkit.MenuRenderer.encodeEnd(MenuRenderer.java:51) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861) at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:370) at com.icesoft.faces.renderkit.dom_html_basic.GridRenderer.encodeChildren(GridRenderer.java:208) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837) at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:358) at com.icesoft.faces.renderkit.dom_html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:96) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837) at com.icesoft.faces.component.util.CustomComponentUtils.renderChild(CustomComponentUtils.java:339) at com.icesoft.faces.component.paneltabset.PanelTabSetRenderer.writeTabCell(PanelTabSetRenderer.java:977) at com.icesoft.faces.component.paneltabset.PanelTabSetRenderer.encodeEnd(PanelTabSetRenderer.java:423) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861) at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:503) at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:497) at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:497) at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:497) at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:497) at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:456) at com.icesoft.faces.application.D2DViewHandler.renderView(D2DViewHandler.java:159) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) at com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:19) at com.icesoft.faces.context.View$2$1.respond(View.java:48) at com.icesoft.faces.webapp.http.servlet.ServletRequestResponse.respondWith(ServletRequestResponse.java:201) at com.icesoft.faces.context.View$2.serve(View.java:77) at com.icesoft.faces.context.View.servePage(View.java:149) at com.icesoft.faces.webapp.http.core.SingleViewServer.service(SingleViewServer.java:52) at com.icesoft.faces.webapp.http.common.ServerProxy.service(ServerProxy.java:11) at com.icesoft.faces.webapp.http.servlet.MainSessionBoundServlet$4.service(MainSessionBoundServlet.java:149) at com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer.service(PathDispatcherServer.java:24) at com.icesoft.faces.webapp.http.servlet.BasicAdaptingServlet.service(BasicAdaptingServlet.java:16) at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23) at com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:53) at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23) at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:131) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:444) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310) at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:696) at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:667) at org.apache.jsp.index_jsp._jspService(index_jsp.java:58) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92) at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126) at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:662) Caused by: com.icesoft.faces.webapp.http.core.SessionExpiredException: User session has expired or it was invalidated. at com.icesoft.faces.webapp.http.servlet.ProxyHttpSession.getAttribute(ProxyHttpSession.java:77) at com.icesoft.faces.webapp.http.servlet.ServletSessionAttributeMap.getAttribute(ServletSessionAttributeMap.java:16) at com.icesoft.faces.context.AbstractAttributeMap.containsKey(AbstractAttributeMap.java:85) at com.sun.faces.mgbean.BeanManager.isBeanInScope(BeanManager.java:177) at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:82) at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54) at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72) at bean.Abgrenzungsreise.(Abgrenzungsreise.java:39) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:308) at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:186) ... 86 more Caused by: java.lang.IllegalStateException: getAttribute: Session already invalidated at org.apache.catalina.session.StandardSession.getAttribute(StandardSession.java:1032) at org.apache.catalina.session.StandardSessionFacade.getAttribute(StandardSessionFacade.java:110) at com.icesoft.faces.webapp.http.servlet.ProxyHttpSession.getAttribute(ProxyHttpSession.java:75) ... 100 more

I recognized that the exception is thrown an half hour after the last user activity.

Answer

BalusC picture BalusC · Jan 28, 2011

The same problem has been reported on the IceFaces forums:

The proposed solutions were:

This was happening for us once we set the asynchronous mode off

<!-- Specifies to the ICEfaces framework that synchronous update mode is to be
used. By default, ICEfaces uses asynchronous update mode to support
server-initiated updates (AJAX push). Setting to true will enable
synchronous update mode and disable AJAX push features. -->
<context-param>
    <param-name>com.icesoft.faces.synchronousUpdate</param-name>
    <param-value>true</param-value>
</context-param>  

When this was false we got the nice little session timed out message. When this was true, session timeout behaviour was stack trace.

and

In the meantime I've switched from ICEfaces 1.8.2 to what's in the svn repository at the moment (1.8.3+). And the behavior has changed. There is no crash anymore.

As to your statement that you aren't using the session anywhere, the stacktrace tells that it is attempting to create a session scoped managed bean when this exception was thrown. So you are definitely using the session :)


Update as per the comments: You should indeed definitely not assign the (request based!!) FacesContext as a static variable. Also, injecting of other beans needs to be taken place by <managed-property> in faces-config.xml. Otherwise it isn't "injecting" at all, but just manually accessing the other bean. With injecting, you're letting JSF do the work to set the other bean as a property of the current bean. An example can be found here.