Buggy code:
public class Discovery { 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 LocatorServiceListener localLocatorServiceListener ; private ServiceTracker locatorServiceTracker ; private Map < IDiscoveryLocator , LocatorServiceListener > locatorListeners ; private EndpointListenerTrackerCustomizer endpointListenerTrackerCustomizer ; private ServiceTracker endpointListenerTracker ; private ServiceTracker advertiserTracker ; private Object advertiserTrackerLock = new Object ( ) ; private BundleTracker bundleTracker ; private EndpointDescriptionBundleTrackerCustomizer bundleTrackerCustomizer ; public Discovery ( BundleContext context ) { } public void start ( ) { } private void logError ( String methodName , String message , Throwable e ) { } 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 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 Discovery . 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 Discovery . EndpointListenerHolder [ ] getMatchingEndpointListenerHolders ( ServiceReference [ ] refs , EndpointDescription description ) { if ( refs == null ) return null ; List results = new ArrayList ( ) ; for ( int i = 0 ; i < ( refs . length ) ; i ++ ) { EndpointListener listener = ( ( EndpointListener ) ( context . getService ( refs [ i ] ) ) ) ; if ( listener == null ) continue ; List filters = PropertiesUtil . getStringPlusProperty ( getMapFromProperties ( refs [ i ] ) , ENDPOINT_LISTENER_SCOPE ) ; String matchingFilter = isMatch ( description , filters ) ; if ( matchingFilter != null ) results . add ( new Discovery . EndpointListenerHolder ( listener , description , matchingFilter ) ) ; } <START_BUG> return ( ( Discovery . EndpointListenerHolder [ ] ) ( results . toArray ( new Discovery . EndpointListenerHolder [ ] { } ) ) ) ; <END_BUG> } private String isMatch ( EndpointDescription description , List filters ) { } private Map getMapFromProperties ( ServiceReference ref ) { } }

Fix:
return ( ( Discovery . EndpointListenerHolder [ ] ) ( results . toArray ( new Discovery . EndpointListenerHolder [ results . size ( ) ] ) ) ) ;