Buggy code:
@ Listener ( primaryOnly = true ) public class InfinispanBeanManager < G , I , T > implements KeyFilter , Batcher , BeanManager < G , I , T > { private final Cache < G , BeanGroupEntry < I , T > > groupCache ; private final String beanName ; private final Cache < BeanKey < I > , BeanEntry < G > > beanCache ; private final BeanFactory < G , I , T > beanFactory ; private final BeanGroupFactory < G , I , T > groupFactory ; private final IdentifierFactory < G > groupIdentifierFactory ; private final IdentifierFactory < I > beanIdentifierFactory ; private final List < KeyAffinityService < ? > > affinityServices = new ArrayList < > ( 2 ) ; private final Registry < String , ? > registry ; private final NodeFactory < Address > nodeFactory ; private final CommandDispatcherFactory dispatcherFactory ; private final ExpirationConfiguration < T > expiration ; private final PassivationConfiguration < T > passivation ; private final AtomicInteger passiveCount = new AtomicInteger ( ) ; private volatile Scheduler < I > scheduler ; private volatile CommandDispatcher < Scheduler < I > > dispatcher ; public InfinispanBeanManager ( InfinispanBeanManagerConfiguration < T > configuration , final Configuration < I , BeanKey < I > , BeanEntry < G > , BeanFactory < G , I , T > > beanConfiguration , final Configuration < G , G , BeanGroupEntry < I , T > , BeanGroupFactory < G , I , T > > groupConfiguration ) { } @ Override public void start ( ) { } @ Override public void stop ( ) { } @ Override public boolean accept ( Object key ) { } @ Override public Affinity getStrictAffinity ( ) { } @ Override public Affinity getWeakAffinity ( I id ) { } void cancel ( Bean < G , I , T > bean ) { } void schedule ( Bean < G , I , T > bean ) { } private Node locatePrimaryOwner ( I id ) { } @ Override public Bean < G , I , T > createBean ( I id , G groupId , T bean ) { } @ Override public Bean < G , I , T > findBean ( I id ) { } @ Override public boolean containsBean ( I id ) { } @ Override public IdentifierFactory < G > getGroupIdentifierFactory ( ) { } @ Override public IdentifierFactory < I > getBeanIdentifierFactory ( ) { } @ Override public Batcher getBatcher ( ) { } @ Override public Batch startBatch ( ) { } @ Override public int getActiveCount ( ) { } @ Override public int getPassiveCount ( ) { } @ CacheEntryPassivated public void passivated ( CacheEntryPassivatedEvent < BeanKey < I > , BeanEntry < G > > event ) { } @ CacheEntryActivated public void activated ( CacheEntryActivatedEvent < BeanKey < I > , BeanEntry < G > > event ) { } @ DataRehashed public void dataRehashed ( DataRehashedEvent < BeanKey < I > , BeanEntry < G > > event ) { } private void schedule ( Cache < BeanKey < I > , BeanEntry < G > > cache , Locality oldLocality , Locality newLocality ) { for ( Object key : cache . getAdvancedCache ( ) . withFlags ( CACHE_MODE_LOCAL , SKIP_CACHE_LOAD , SKIP_LOCKING ) . keySet ( ) ) { if ( this . accept ( key ) ) { @ SuppressWarnings ( "unchecked" ) <START_BUG> I id = ( ( BeanKey < I > ) ( key ) ) . getId ( ) ; <END_BUG> if ( ( ! ( oldLocality . isLocal ( id ) ) ) && ( newLocality . isLocal ( id ) ) ) { this . scheduler . schedule ( id ) ; } } } } private class SchedulableBean implements Bean < G , I , T > { private final Bean < G , I , T > bean ; SchedulableBean ( Bean < G , I , T > bean ) { } @ Override public I getId ( ) { } @ Override public G getGroupId ( ) { } @ Override public void remove ( RemoveListener < T > listener ) { } @ Override public boolean isExpired ( ) { } @ Override public T acquire ( ) { } @ Override public boolean release ( ) { } @ Override public void close ( ) { } } }

Fix:
I id = ( ( I ) ( key ) ) ;