Buggy code:
public class ReferenceListRecipe extends AbstractServiceReferenceRecipe { private static final Logger LOGGER = LoggerFactory . getLogger ( ReferenceListRecipe . class ) ; private final ReferenceListMetadata metadata ; private final List < ReferenceListRecipe . ManagedCollection > collections = new ArrayList < ReferenceListRecipe . ManagedCollection > ( ) ; private final DynamicCollection < ReferenceListRecipe . ServiceDispatcher > storage = new DynamicCollection < ReferenceListRecipe . ServiceDispatcher > ( ) ; private final List < ReferenceListRecipe . ServiceDispatcher > unboundDispatchers = new ArrayList < ReferenceListRecipe . ServiceDispatcher > ( ) ; private final Object monitor = new Object ( ) ; public ReferenceListRecipe ( String name , ExtendedBlueprintContainer blueprintContainer , ReferenceListMetadata metadata , CollectionRecipe listenersRecipe , List < Recipe > explicitDependencies ) { } @ Override protected Object internalCreate ( ) throws ComponentDefinitionException { } protected void retrack ( ) { } protected void track ( ServiceReference reference ) { } protected void untrack ( ServiceReference reference ) { } protected ReferenceListRecipe . ServiceDispatcher findDispatcher ( ServiceReference reference ) { } protected ReferenceListRecipe . ManagedCollection getManagedCollection ( boolean useReferences ) { } public class ServiceDispatcher implements Callable < Object > { public ServiceReference reference ; public Object service ; public Object proxy ; public ServiceDispatcher ( ServiceReference reference ) throws Exception { } public synchronized void destroy ( ) { if ( ( reference ) != null ) { ServiceReference ref = reference ; reference = null ; service = null ; proxy = null ; Bundle bundle = ref . getBundle ( ) ; if ( bundle != null ) { BundleContext ctx = bundle . getBundleContext ( ) ; if ( ctx != null ) { <START_BUG> ctx . ungetService ( reference ) ; <END_BUG> } } } } public synchronized Object call ( ) throws Exception { } } public class ProvidedObject implements AggregateConverter . Convertible { public Object convert ( ReifiedType type ) { } } public static class ManagedCollection extends AbstractCollection implements List , RandomAccess { protected final DynamicCollection < ReferenceListRecipe . ServiceDispatcher > dispatchers ; protected boolean references ; public ManagedCollection ( boolean references , DynamicCollection < ReferenceListRecipe . ServiceDispatcher > dispatchers ) { } public boolean addDispatcher ( ReferenceListRecipe . ServiceDispatcher dispatcher ) { } public boolean removeDispatcher ( ReferenceListRecipe . ServiceDispatcher dispatcher ) { } public DynamicCollection < ReferenceListRecipe . ServiceDispatcher > getDispatchers ( ) { } public Iterator iterator ( ) { } public int size ( ) { } @ Override public boolean add ( Object o ) { } @ Override public boolean remove ( Object o ) { } @ Override public boolean addAll ( Collection c ) { } @ Override public void clear ( ) { } @ Override public boolean retainAll ( Collection c ) { } @ Override public boolean removeAll ( Collection c ) { } public Object get ( int index ) { } public int indexOf ( Object o ) { } public int lastIndexOf ( Object o ) { } public ListIterator listIterator ( ) { } public ListIterator listIterator ( int index ) { } public List < ReferenceListRecipe . ServiceDispatcher > subList ( int fromIndex , int toIndex ) { } public Object set ( int index , Object element ) { } public void add ( int index , Object element ) { } public Object remove ( int index ) { } public boolean addAll ( int index , Collection c ) { } public class ManagedListIterator implements ListIterator { protected final ListIterator < ReferenceListRecipe . ServiceDispatcher > iterator ; public ManagedListIterator ( ListIterator < ReferenceListRecipe . ServiceDispatcher > iterator ) { } public boolean hasNext ( ) { } public Object next ( ) { } public boolean hasPrevious ( ) { } public Object previous ( ) { } public int nextIndex ( ) { } public int previousIndex ( ) { } public void remove ( ) { } public void set ( Object o ) { } public void add ( Object o ) { } } } }

Fix:
ctx . ungetService ( ref ) ;