title: request.getSession(false) causes java.lang.IllegalStateException
body: <p>When I try to get the session from the request, it causes a null pointer exception if the session is expired. Given below is a part of the code. I get exception on the third line.  </p>
  
  <pre><code>public void doFilter(ServletRequest req, ServletResponse res,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest httpReq = (HttpServletRequest) req;
  HttpSession session = httpReq.getSession(false);
  </code></pre>
  
  <p>And here is the stacktrace :</p>
  
  <pre><code>java.lang.IllegalStateException: getLastAccessedTime: Session already invalidated
  at org.apache.catalina.session.StandardSession.getLastAccessedTime(StandardSession.java:423)
  at org.apache.catalina.session.StandardSessionFacade.getLastAccessedTime(StandardSessionFacade.java:84)
  at com.myapp.admin.CustomerContext.valueUnbound(CustomerContext.java:806)
  at org.apache.catalina.session.StandardSession.removeAttributeInternal(StandardSession.java:1686)
  at org.apache.catalina.session.StandardSession.expire(StandardSession.java:801)
  at org.apache.catalina.session.StandardSession.isValid(StandardSession.java:576)
  at org.apache.catalina.connector.Request.doGetSession(Request.java:2386)
  at org.apache.catalina.connector.Request.getSession(Request.java:2120)
  at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:833)
  at com.myapp.ui.web.filter.ApplicationSessionFilter.doFilter(ApplicationSessionFilter.java:45)
  at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
  at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at com.myapp.ui.web.filter.ErrorFilter.doFilter(ErrorFilter.java:42)
  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:233)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
  at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
  at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
  at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:776)
  at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:705)
  at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:898)
  at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
  at java.lang.Thread.run(Thread.java:662)
  </code></pre>