Buggy code:
public class PersistentValve extends ValveBase { public PersistentValve ( ) { } private static final String info = "org.apache.catalina.valves.PersistentValve//1.0" ; @ Override public String getInfo ( ) { } @ Override public void invoke ( Request request , Response response ) throws IOException , ServletException { Context context = request . getContext ( ) ; if ( context == null ) { response . sendError ( SC_INTERNAL_SERVER_ERROR , sm . getString ( "standardHost.noContext" ) ) ; return ; } Thread . currentThread ( ) . setContextClassLoader ( context . getLoader ( ) . getClassLoader ( ) ) ; String sessionId = request . getRequestedSessionId ( ) ; Manager manager = context . getManager ( ) ; if ( ( sessionId != null ) && ( manager != null ) ) { if ( manager instanceof PersistentManager ) { Store store = ( ( PersistentManager ) ( manager ) ) . getStore ( ) ; if ( store != null ) { Session session = null ; try { session = store . load ( sessionId ) ; } catch ( Exception e ) { container . getLogger ( ) . error ( "deserializeError" ) ; } if ( session != null ) { if ( ( ! ( session . isValid ( ) ) ) || ( isSessionStale ( session , System . currentTimeMillis ( ) ) ) ) { if ( container . getLogger ( ) . isDebugEnabled ( ) ) { container . getLogger ( ) . debug ( "session<seq2seq4repair_space>swapped<seq2seq4repair_space>in<seq2seq4repair_space>is<seq2seq4repair_space>invalid<seq2seq4repair_space>or<seq2seq4repair_space>expired" ) ; } session . expire ( ) ; store . remove ( sessionId ) ; } else { session . setManager ( manager ) ; manager . add ( session ) ; session . access ( ) ; session . endAccess ( ) ; } } } } } if ( container . getLogger ( ) . isDebugEnabled ( ) ) { container . getLogger ( ) . debug ( ( "sessionId:<seq2seq4repair_space>" + sessionId ) ) ; } getNext ( ) . invoke ( request , response ) ; if ( ! ( request . isAsync ( ) ) ) { Session hsess ; try { <START_BUG> hsess = request . getSessionInternal ( ) ; <END_BUG> } catch ( Exception ex ) { hsess = null ; } String newsessionId = null ; if ( hsess != null ) { newsessionId = hsess . getIdInternal ( ) ; } if ( container . getLogger ( ) . isDebugEnabled ( ) ) { container . getLogger ( ) . debug ( ( "newsessionId:<seq2seq4repair_space>" + newsessionId ) ) ; } if ( newsessionId != null ) { if ( manager instanceof PersistentManager ) { Session session = manager . findSession ( newsessionId ) ; Store store = ( ( PersistentManager ) ( manager ) ) . getStore ( ) ; if ( ( ( ( store != null ) && ( session != null ) ) && ( session . isValid ( ) ) ) && ( ! ( isSessionStale ( session , System . currentTimeMillis ( ) ) ) ) ) { store . save ( session ) ; ( ( PersistentManager ) ( manager ) ) . removeSuper ( session ) ; session . recycle ( ) ; } else { if ( container . getLogger ( ) . isDebugEnabled ( ) ) { container . getLogger ( ) . debug ( ( ( ( ( ( ( ( "newsessionId<seq2seq4repair_space>store:<seq2seq4repair_space>" + store ) + "<seq2seq4repair_space>session:<seq2seq4repair_space>" ) + session ) + "<seq2seq4repair_space>valid:<seq2seq4repair_space>" ) + ( session == null ? "N//A" : Boolean . toString ( session . isValid ( ) ) ) ) + "<seq2seq4repair_space>stale:<seq2seq4repair_space>" ) + ( isSessionStale ( session , System . currentTimeMillis ( ) ) ) ) ) ; } } } else { if ( container . getLogger ( ) . isDebugEnabled ( ) ) { container . getLogger ( ) . debug ( ( "newsessionId<seq2seq4repair_space>Manager:<seq2seq4repair_space>" + manager ) ) ; } } } } } protected boolean isSessionStale ( Session session , long timeNow ) { } }

Fix:
hsess = request . getSessionInternal ( false ) ;