Buggy code:
@ Listener public class InfinispanSessionManager < V , L > implements KeyGenerator < String > , KeyFilter , Batcher , SessionManager < L > { private final SessionContext context ; final Cache < String , V > cache ; private final SessionFactory < V , L > factory ; private final SessionIdentifierFactory idFactory ; private final KeyAffinityService < String > affinity ; private final Registry < String , Void > registry ; private final NodeFactory < Address > nodeFactory ; private final List < Scheduler < ImmutableSession > > schedulers = new CopyOnWriteArrayList < > ( ) ; private final int maxActiveSessions ; private volatile Time defaultMaxInactiveInterval = new Time ( 30 , TimeUnit . MINUTES ) ; private final boolean alwaysSerialize ; public InfinispanSessionManager ( SessionContext context , SessionIdentifierFactory idFactory , Cache < String , V > cache , SessionFactory < V , L > factory , KeyAffinityServiceFactory affinityFactory , Registry < String , Void > registry , NodeFactory < Address > nodeFactory , JBossWebMetaData metaData ) { } @ Override public void start ( ) { } @ Override public void stop ( ) { } @ Override public boolean accept ( Object key ) { } @ Override public Batch startBatch ( ) { } @ Override public String locate ( String sessionId ) { } private Address locatePrimaryOwner ( String sessionId ) { } @ Override public Batcher getBatcher ( ) { } @ Override public long getDefaultMaxInactiveInterval ( TimeUnit unit ) { } @ Override public void setDefaultMaxInactiveInterval ( long value , TimeUnit unit ) { } @ Override public String getKey ( ) { } @ Override public String createSessionId ( ) { } @ Override public boolean containsSession ( String id ) { } @ Override public Session < L > findSession ( String id ) { } @ Override public Session < L > createSession ( String id ) { } @ Override public ImmutableSession viewSession ( String id ) { } @ Override public Set < String > getActiveSessions ( ) { } @ Override public Set < String > getLocalSessions ( ) { } private Set < String > getSessions ( Flag ... flags ) { } @ CacheEntryActivated public void activated ( CacheEntryActivatedEvent < String , ? > event ) { } @ CacheEntryPassivated public void passivated ( CacheEntryPassivatedEvent < String , ? > event ) { } @ CacheEntryRemoved public void removed ( CacheEntryRemovedEvent < String , ? > event ) { } @ TopologyChanged public void topologyChanged ( TopologyChangedEvent < String , ? > event ) { if ( event . isPre ( ) ) return ; Cache < String , ? > cache = event . getCache ( ) ; Address localAddress = cache . getCacheManager ( ) . getAddress ( ) ; ConsistentHash oldHash = event . getConsistentHashAtStart ( ) ; ConsistentHash newHash = event . getConsistentHashAtEnd ( ) ; Set < Address > oldAddresses = new java . util . HashSet ( oldHash . getMembers ( ) ) ; oldAddresses . removeAll ( newHash . getMembers ( ) ) ; if ( ! ( oldAddresses . isEmpty ( ) ) ) { for ( Object key : cache . getAdvancedCache ( ) . withFlags ( CACHE_MODE_LOCAL , SKIP_CACHE_LOAD , SKIP_LOCKING ) . keySet ( ) ) { <START_BUG> if ( key instanceof String ) { <END_BUG> String sessionId = ( ( String ) ( key ) ) ; Address oldOwner = oldHash . locatePrimaryOwner ( sessionId ) ; if ( oldAddresses . contains ( oldOwner ) ) { Address newOwner = newHash . locatePrimaryOwner ( sessionId ) ; if ( localAddress . equals ( newOwner ) ) { boolean started = cache . startBatch ( ) ; try { V value = this . factory . findValue ( sessionId ) ; if ( value != null ) { ROOT_LOGGER . debugf ( "Scheduling<seq2seq4repair_space>expiration<seq2seq4repair_space>of<seq2seq4repair_space>session<seq2seq4repair_space>%s<seq2seq4repair_space>on<seq2seq4repair_space>behalf<seq2seq4repair_space>of<seq2seq4repair_space>previous<seq2seq4repair_space>owner:<seq2seq4repair_space>%s" , sessionId , oldOwner ) ; ImmutableSession session = this . factory . createImmutableSession ( sessionId , value ) ; for ( Scheduler < ImmutableSession > scheduler : this . schedulers ) { scheduler . cancel ( session ) ; scheduler . schedule ( session ) ; } } } finally { if ( started ) { cache . endBatch ( false ) ; } } } else { ROOT_LOGGER . tracef ( "Expiration<seq2seq4repair_space>of<seq2seq4repair_space>session<seq2seq4repair_space>%s<seq2seq4repair_space>will<seq2seq4repair_space>be<seq2seq4repair_space>scheduled<seq2seq4repair_space>by<seq2seq4repair_space>node<seq2seq4repair_space>%s<seq2seq4repair_space>on<seq2seq4repair_space>behalf<seq2seq4repair_space>of<seq2seq4repair_space>previous<seq2seq4repair_space>owner:<seq2seq4repair_space>%s" , sessionId , newOwner , oldOwner ) ; } } } } } } static void triggerPrePassivationEvents ( ImmutableSession session ) { } static void triggerPostActivationEvents ( ImmutableSession session ) { } private static List < HttpSessionActivationListener > findListeners ( ImmutableSession session ) { } private static class SchedulableSession < L > implements Session < L > { private final Session < L > session ; private final List < Scheduler < ImmutableSession > > schedulers ; private final boolean alwaysSerialize ; SchedulableSession ( Session < L > session , List < Scheduler < ImmutableSession > > schedulers , boolean alwaysSerialize ) { } @ Override public String getId ( ) { } @ Override public SessionMetaData getMetaData ( ) { } @ Override public boolean isValid ( ) { } @ Override public void invalidate ( ) { } @ Override public SessionAttributes getAttributes ( ) { } @ Override public SessionContext getContext ( ) { } @ Override public void close ( ) { } @ Override public L getLocalContext ( ) { } } }

Fix:
if ( this . accept ( key ) ) {