Buggy code:
@ Listener ( sync = false ) public class RegistryService < K , V > extends AsynchronousService < Registry < K , V > > implements Registry < K , V > { static final Address LOCAL_ADDRESS = new Address ( ) { } ; @ SuppressWarnings ( "rawtypes" ) private final InjectedValue < Cache > cacheRef = new InjectedValue < Cache > ( ) ; private final RegistryEntryProvider < K , V > provider ; private final Set < Listener < K , V > > listeners = new CopyOnWriteArraySet < Listener < K , V > > ( ) ; private volatile Cache < Address , Map . Entry < K , V > > cache ; public RegistryService ( RegistryEntryProvider < K , V > provider ) { } public ServiceBuilder < Registry < K , V > > build ( ServiceTarget target , ServiceName serviceName , ServiceName cacheServiceName ) { } @ SuppressWarnings ( "rawtypes" ) public Injector < Cache > getCacheInjector ( ) { } @ Override public Registry < K , V > getValue ( ) { } @ Override public String getName ( ) { } @ Override public void addListener ( Listener < K , V > listener ) { } @ Override public void removeListener ( Listener < K , V > listener ) { } @ Override public Map < K , V > getEntries ( ) { } @ Override public Map . Entry < K , V > getLocalEntry ( ) { } @ Override public Map . Entry < K , V > getRemoteEntry ( Object address ) { } @ SuppressWarnings ( "unchecked" ) @ Override protected void start ( ) { } @ Override public void refreshLocalEntry ( ) { } void addCacheEntry ( Cache < Address , Map . Entry < K , V > > cache ) { } @ Override protected void stop ( ) { } static Address getLocalAddress ( Cache < ? , ? > cache ) { } @ ViewChanged public void viewChanged ( final ViewChangedEvent event ) { RegistryService < K , V > . Operation < Set < K > > operation = new Operation < Set < K > > ( ) { @ Override public Set < K > invoke ( Cache < Address , Map . Entry < K , V > > cache ) { Collection < Address > oldMembers = event . getOldMembers ( ) ; Collection < Address > newMembers = event . getNewMembers ( ) ; Set < K > removed = new HashSet < K > ( ) ; for ( Address member : oldMembers ) { if ( ! ( newMembers . contains ( member ) ) ) { <START_BUG> Map . Entry < K , V > old = cache . remove ( member ) ; <END_BUG> if ( old != null ) { removed . add ( old . getKey ( ) ) ; } } } Address localAddress = event . getLocalAddress ( ) ; if ( ( ! ( oldMembers . contains ( localAddress ) ) ) && ( newMembers . contains ( localAddress ) ) ) { RegistryService . this . addCacheEntry ( cache ) ; } return removed ; } } ; Set < K > removed = this . invoke ( operation ) ; if ( ! ( removed . isEmpty ( ) ) ) { for ( Listener < K , V > listener : this . listeners ) { listener . removedEntries ( removed ) ; } } } @ CacheEntryCreated public void created ( CacheEntryCreatedEvent < Address , Map . Entry < K , V > > event ) { } @ CacheEntryModified public void modified ( CacheEntryModifiedEvent < Address , Map . Entry < K , V > > event ) { } @ CacheEntryRemoved public void removed ( CacheEntryRemovedEvent < Address , Map . Entry < K , V > > event ) { } < R > R invoke ( RegistryService < K , V > . Operation < R > operation ) { } abstract class Operation < R > implements CacheInvoker . Operation < Address , Map . Entry < K , V > , R > { } }

Fix:
Map . Entry < K , V > old = cache . getAdvancedCache ( ) . withFlags ( CACHE_MODE_LOCAL ) . remove ( member ) ;