Buggy code:
public class OpenSessionInViewFilter extends OncePerRequestFilter { public static final String DEFAULT_SESSION_FACTORY_BEAN_NAME = "sessionFactory" ; private String sessionFactoryBeanName = OpenSessionInViewFilter . DEFAULT_SESSION_FACTORY_BEAN_NAME ; private boolean singleSession = true ; private FlushMode flushMode = FlushMode . MANUAL ; public void setSessionFactoryBeanName ( String sessionFactoryBeanName ) { } protected String getSessionFactoryBeanName ( ) { } public void setSingleSession ( boolean singleSession ) { } protected boolean isSingleSession ( ) { } public void setFlushMode ( FlushMode flushMode ) { } protected FlushMode getFlushMode ( ) { } @ Override protected void doFilterInternal ( HttpServletRequest request , HttpServletResponse response , FilterChain filterChain ) throws IOException , ServletException { AsyncExecutionChain chain = AsyncExecutionChain . getForCurrentRequest ( request ) ; SessionFactory sessionFactory = lookupSessionFactory ( request ) ; boolean participate = false ; if ( isSingleSession ( ) ) { if ( TransactionSynchronizationManager . hasResource ( sessionFactory ) ) { participate = true ; } else { logger . debug ( "Opening<seq2seq4repair_space>single<seq2seq4repair_space>Hibernate<seq2seq4repair_space>Session<seq2seq4repair_space>in<seq2seq4repair_space>OpenSessionInViewFilter" ) ; Session session = getSession ( sessionFactory ) ; SessionHolder sessionHolder = new SessionHolder ( session ) ; TransactionSynchronizationManager . bindResource ( sessionFactory , sessionHolder ) ; chain . push ( getAsyncCallable ( request , sessionFactory , sessionHolder ) ) ; } } else { if ( SessionFactoryUtils . isDeferredCloseActive ( sessionFactory ) ) { participate = true ; } else { SessionFactoryUtils . initDeferredClose ( sessionFactory ) ; } } try { filterChain . doFilter ( request , response ) ; } finally { if ( ! participate ) { if ( isSingleSession ( ) ) { SessionHolder sessionHolder = ( ( SessionHolder ) ( TransactionSynchronizationManager . unbindResource ( sessionFactory ) ) ) ; if ( ! ( chain . pop ( ) ) ) { return ; } logger . debug ( "Closing<seq2seq4repair_space>single<seq2seq4repair_space>Hibernate<seq2seq4repair_space>Session<seq2seq4repair_space>in<seq2seq4repair_space>OpenSessionInViewFilter" ) ; closeSession ( sessionHolder . getSession ( ) , sessionFactory ) ; } else { <START_BUG> if ( ! ( chain . pop ( ) ) ) { <END_BUG> throw new IllegalStateException ( "Deferred<seq2seq4repair_space>close<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>supported<seq2seq4repair_space>with<seq2seq4repair_space>async<seq2seq4repair_space>requests." ) ; } SessionFactoryUtils . processDeferredClose ( sessionFactory ) ; } } } } protected SessionFactory lookupSessionFactory ( HttpServletRequest request ) { } protected SessionFactory lookupSessionFactory ( ) { } protected Session getSession ( SessionFactory sessionFactory ) throws DataAccessResourceFailureException { } protected void closeSession ( Session session , SessionFactory sessionFactory ) { } private AbstractDelegatingCallable getAsyncCallable ( final HttpServletRequest request , final SessionFactory sessionFactory , final SessionHolder sessionHolder ) { } }

Fix:
if ( chain . isAsyncStarted ( ) ) {