Buggy code:
public class EndpointDescriptionLocator { private BundleContext context ; private IExecutor executor ; private ServiceInfoFactory serviceInfoFactory ; private ServiceRegistration defaultServiceInfoFactoryRegistration ; private Object serviceInfoFactoryTrackerLock = new Object ( ) ; private ServiceTracker serviceInfoFactoryTracker ; private DiscoveredEndpointDescriptionFactory defaultEndpointDescriptionFactory ; private ServiceRegistration defaultEndpointDescriptionFactoryRegistration ; private Object endpointDescriptionFactoryTrackerLock = new Object ( ) ; private ServiceTracker endpointDescriptionFactoryTracker ; private ServiceRegistration defaultEndpointDescriptionReaderRegistration ; private EventManager eventManager ; private ListenerQueue eventQueue ; private EndpointDescriptionLocator . LocatorServiceListener localLocatorServiceListener ; private ServiceTracker locatorServiceTracker ; private Map < IDiscoveryLocator , EndpointDescriptionLocator . LocatorServiceListener > locatorListeners ; private ServiceTracker endpointListenerTracker ; private ServiceTracker advertiserTracker ; private Object advertiserTrackerLock = new Object ( ) ; private BundleTracker bundleTracker ; private EndpointDescriptionLocator . EndpointDescriptionBundleTrackerCustomizer bundleTrackerCustomizer ; public EndpointDescriptionLocator ( BundleContext context ) { } public void start ( ) { } private void logError ( String methodName , String message , Throwable e ) { } private void trace ( String methodName , String message ) { } public void close ( ) { } public IDiscoveryAdvertiser [ ] getDiscoveryAdvertisers ( ) { } private void openLocator ( IDiscoveryLocator locator ) { } private void shutdownLocator ( IDiscoveryLocator locator ) { } void queueEndpointDescription ( EndpointListener listener , EndpointDescription endpointDescription , String matchingFilters , boolean discovered ) { } Collection < EndpointDescription > getAllDiscoveredEndpointDescriptions ( ) { } void queueEndpointDescription ( EndpointDescription endpointDescription , boolean discovered ) { } private void processInitialLocatorServices ( final IDiscoveryLocator locator , final EndpointDescriptionLocator . LocatorServiceListener locatorListener ) { } void shutdownLocators ( ) { } private class EndpointListenerEvent { private EndpointListener endpointListener ; private EndpointDescription endpointDescription ; private String matchingFilter ; private boolean discovered ; public EndpointListenerEvent ( EndpointListener endpointListener , EndpointDescription endpointDescription , String matchingFilter , boolean discovered ) { } public EndpointListener getEndpointListener ( ) { } public EndpointDescription getEndointDescription ( ) { } public String getMatchingFilter ( ) { } public boolean isDiscovered ( ) { } } private class LocatorTrackerCustomizer implements ServiceTrackerCustomizer { public Object addingService ( ServiceReference reference ) { } public void modifiedService ( ServiceReference reference , Object service ) { } public void removedService ( ServiceReference reference , Object service ) { } } public IServiceInfoFactory getServiceInfoFactory ( ) { } public IDiscoveredEndpointDescriptionFactory getDiscoveredEndpointDescriptionFactory ( ) { } private Object endpointListenerServiceTrackerLock = new Object ( ) ; public EndpointDescriptionLocator . EndpointListenerHolder [ ] getMatchingEndpointListenerHolders ( EndpointDescription description ) { } public class EndpointListenerHolder { private EndpointListener listener ; private EndpointDescription description ; private String matchingFilter ; public EndpointListenerHolder ( EndpointListener l , EndpointDescription d , String f ) { } public EndpointListener getListener ( ) { } public EndpointDescription getDescription ( ) { } public String getMatchingFilter ( ) { } } public EndpointDescriptionLocator . EndpointListenerHolder [ ] getMatchingEndpointListenerHolders ( ServiceReference [ ] refs , EndpointDescription description ) { } private String isMatch ( EndpointDescription description , List < String > filters ) { } private Map getMapFromProperties ( ServiceReference ref ) { } class EndpointDescriptionBundleTrackerCustomizer implements BundleTrackerCustomizer { private static final String REMOTESERVICE_MANIFESTHEADER = "Remote-Service" ; private static final String XML_FILE_PATTERN = "*.xml" ; private Map < Long , Collection < EndpointDescription > > bundleDescriptionMap = Collections . synchronizedMap ( new HashMap < Long , Collection < EndpointDescription > > ( ) ) ; private Object endpointDescriptionReaderTrackerLock = new Object ( ) ; private ServiceTracker endpointDescriptionReaderTracker ; private IEndpointDescriptionReader getEndpointDescriptionReader ( ) { } public Object addingBundle ( Bundle bundle , BundleEvent event ) { } private void handleAddingBundle ( Bundle bundle ) { } private void handleEndpointDescriptionPath ( Bundle bundle , String remoteServicesHeaderValue ) { } private EndpointDescription [ ] handleEndpointDescriptionFile ( Bundle bundle , URL fileURL ) { } private void logError ( String method , String message , Throwable t ) { } public void modifiedBundle ( Bundle bundle , BundleEvent event , Object object ) { } public void removedBundle ( Bundle bundle , BundleEvent event , Object object ) { } private void handleRemovedBundle ( Bundle bundle ) { } public void close ( ) { } } class LocatorServiceListener implements IServiceListener { private Object listenerLock = new Object ( ) ; private IDiscoveryLocator locator ; private List < EndpointDescription > discoveredEndpointDescriptions = new ArrayList ( ) ; public LocatorServiceListener ( IDiscoveryLocator locator ) { } public void serviceDiscovered ( IServiceEvent anEvent ) { } public void serviceUndiscovered ( IServiceEvent anEvent ) { } private boolean matchServiceID ( IServiceID serviceId ) { } void handleService ( IServiceInfo serviceInfo , boolean discovered ) { } private void handleOSGiServiceEndpoint ( IServiceID serviceId , IServiceInfo serviceInfo , boolean discovered ) { } public void handleEndpointDescription ( EndpointDescription endpointDescription , boolean discovered ) { } public Collection < EndpointDescription > getEndpointDescriptions ( ) { } private void logWarning ( String methodName , String message ) { } private void logError ( String methodName , String message ) { } private void logError ( String methodName , String message , Throwable t ) { } private DiscoveredEndpointDescription getDiscoveredEndpointDescription ( IServiceID serviceId , IServiceInfo serviceInfo , boolean discovered ) { final String methodName = "getDiscoveredEndpointDescription" ; IDiscoveredEndpointDescriptionFactory factory = getDiscoveredEndpointDescriptionFactory ( ) ; if ( factory == null ) { logError ( methodName , ( ( ( "No<seq2seq4repair_space>IEndpointDescriptionFactory<seq2seq4repair_space>found,<seq2seq4repair_space>could<seq2seq4repair_space>not<seq2seq4repair_space>create<seq2seq4repair_space>EndpointDescription<seq2seq4repair_space>for<seq2seq4repair_space>" + ( discovered ? "discovered" : "undiscovered" ) ) + "<seq2seq4repair_space>serviceInfo=" ) + serviceInfo ) ) ; return null ; } try { <START_BUG> return discovered ? factory . createDiscoveredEndpointDescription ( locator , serviceInfo ) : factory . getUndiscoveredEndpointDescription ( locator , serviceId ) ; <END_BUG> } catch ( Exception e ) { logError ( methodName , ( "Exception<seq2seq4repair_space>calling<seq2seq4repair_space>IEndpointDescriptionFactory." + ( discovered ? "createDiscoveredEndpointDescription" : "getUndiscoveredEndpointDescription" ) ) , e ) ; return null ; } catch ( NoClassDefFoundError e ) { logError ( methodName , ( "NoClassDefFoundError<seq2seq4repair_space>calling<seq2seq4repair_space>IEndpointDescriptionFactory." + ( discovered ? "createDiscoveredEndpointDescription" : "getUndiscoveredEndpointDescription" ) ) , e ) ; return null ; } } public synchronized void close ( ) { } } }

Fix:
return discovered ? factory . createDiscoveredEndpointDescription ( locator , serviceInfo ) : factory . removeDiscoveredEndpointDescription ( locator , serviceId ) ;