/**
  * Shut down an ordered list of instances. The list passed to this method is treated as a live,
  * mutable list so any instances added to this list as shutdown is occurring will also be shut
  * down.
  *
  * @param instances the list of instances to shutdown
  */
 @SuppressWarnings({"SynchronizationOnLocalVariableOrMethodParameter"})
 private void destroyInstances(List<Pair> instances) {
   while (true) {
     Pair toDestroy;
     synchronized (instances) {
       if (instances.size() == 0) {
         return;
       }
       toDestroy = instances.remove(instances.size() - 1);
     }
     ScopedComponent component = toDestroy.component;
     try {
       Object instance = toDestroy.instance;
       component.stopInstance(instance);
     } catch (Fabric3Exception e) {
       // log the error from destroy but continue
       monitor.destructionError(component.getUri(), component.getContributionUri(), e);
     }
   }
 }