title: java.lang.IllegalStateException: getAttribute: Session already invalidated
body: <p>I am getting the following exception after I invalidate the portletRequest session in my code</p>
  
  <pre><code>Aug 27, 2013 7:07:13 AM org.apache.catalina.core.ApplicationDispatcher invoke
  SEVERE: Servlet.service() for servlet xyzapplication Servlet threw exception java.lang.IllegalStateException: getAttribute: Session already invalidated
      at org.apache.catalina.session.StandardSession.getAttribute(StandardSession.java:1165)
      at org.apache.catalina.session.StandardSessionFacade.getAttribute(StandardSessionFacade.java:122)
      at com.liferay.portal.servlet.SharedSessionWrapper.getAttribute(SharedSessionWrapper.java:75)
      at com.liferay.portlet.PortletSessionImpl.getAttribute(PortletSessionImpl.java:55)
      at org.springframework.web.portlet.context.PortletRequestAttributes.updateAccessedSessionAttributes(PortletRequestAttributes.java:256)
      at org.springframework.web.context.request.AbstractRequestAttributes.requestCompleted(AbstractRequestAttributes.java:48)
      at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:552)
      at org.springframework.web.portlet.FrameworkPortlet.processAction(FrameworkPortlet.java:460)
      at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
      at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
      at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:111)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
      at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
      at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
      at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:534)
      at com.liferay.portlet.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:579)
      at com.liferay.portlet.InvokerPortletImpl.processAction(InvokerPortletImpl.java:294)
      at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:944)
      at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:688)
      at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:249)
      at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
      at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:176)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
      at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:560)
      at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:537)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
      at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:294)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
      at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:138)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
      at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:335)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
      at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:123)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
      at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:294)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
      at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:241)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
      at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:246)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
      at com.liferay.portal.servlet.filters.sso.ntlm.NtlmPostFilter.processFilter(NtlmPostFilter.java:83)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
      at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:80)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
      at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.processFilter(VirtualHostFilter.java:216)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:187)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:167)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:167)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:187)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at com.googlecode.psiprobe.Tomcat60AgentValve.invoke(Tomcat60AgentValve.java:30)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:722) 
  </code></pre>
  
  <p>and my session invalidation code is as follows: 
  By the way this method is called from another another method which has <code>@ActionMapping</code> tag annotated with it.</p>
  
  <pre><code> private void exit(PortletRequest request, ActionResponse response) {
      logger.debug("Entering exit");
      String exitURL = Constants.EXIT_URL;
      request.getPortletSession().invalidate();
      try {
          response.sendRedirect(exitURL);
      } catch (IOException ex) {
          logger.error("Error: IOException: {}", ex.getMessage());
          throw new RuntimeException(ex);
      }
  
      logger.debug("Exiting exit");
  }
  </code></pre>
  
  <p>I found an already existing question in stackoverflow relating to session invalidation 
  <a href="https://stackoverflow.com/questions/4827035/illegalstateexception-getattribute-session-already-invalidated">IllegalStateException: getAttribute: Session already invalidated</a>
  but I couldn't get much out of it in my case.</p>
  
  <p>Can someone help me how to approach this problem as this error occurs, when the control goes to Spring code and because of which I am not able to approach fixing this problem?</p>