Program: 152882
Project: 152882
Buggy source:
/** 
 * Shutdown the extender and all bundled managed by it. Shutdown of contexts is in the topological order of the dependency graph formed by the service references.
 */
protected void shutdown(){
synchronized (monitor) {
    if (isClosed)     return;
 else     isClosed=true;
  }
  log.info("String_Node_Str" + bundleContext.getBundle().getSymbolicName() + "String_Node_Str"+ extenderVersion+ "String_Node_Str");
  stopTimer();
  if (contextListener != null) {
    bundleContext.removeBundleListener(contextListener);
    contextListener=null;
  }
  if (nsListener != null) {
    bundleContext.removeBundleListener(nsListener);
    nsListener=null;
  }
  Bundle[] bundles=new Bundle[managedContexts.size()];
  int i=0;
  for (Iterator it=managedContexts.values().iterator(); it.hasNext(); ) {
    ConfigurableOsgiBundleApplicationContext context=(ConfigurableOsgiBundleApplicationContext)it.next();
    bundles[i++]=context.getBundle();
  }
  bundles=shutdownDependencySorter.computeServiceDependencyGraph(bundles);
  boolean debug=log.isDebugEnabled();
  StringBuffer buffer=new StringBuffer();
  if (debug) {
    buffer.append("String_Node_Str");
    for (i=0; i < bundles.length; i++) {
      buffer.append("String_Node_Str" + bundles[i].getSymbolicName() + "String_Node_Str");
    }
    buffer.append("String_Node_Str");
    log.debug(buffer);
  }
  final List taskList=new ArrayList(managedContexts.size());
  final List closedContexts=Collections.synchronizedList(new ArrayList());
  final Object[] contextClosingDown=new Object[1];
  for (i=0; i < bundles.length; i++) {
    Long id=new Long(bundles[i].getBundleId());
    final ConfigurableOsgiBundleApplicationContext context=(ConfigurableOsgiBundleApplicationContext)managedContexts.get(id);
    if (context != null) {
      closedContexts.add(context);
      taskList.add(new Runnable(){
        private final String toString="String_Node_Str" + context.getDisplayName();
        public void run(){
          contextClosingDown[0]=context;
          closedContexts.remove(context);
          if (log.isDebugEnabled())           log.debug("String_Node_Str" + context.getDisplayName());
          context.close();
        }
        public String toString(){
          return toString;
        }
      }
);
    }
  }
  final Runnable[] tasks=(Runnable[])taskList.toArray(new Runnable[taskList.size()]);
  for (int j=0; j < tasks.length; j++) {
    if (RunnableTimedExecution.execute(tasks[j],extenderConfiguration.getShutdownWaitTime(),shutdownTaskExecutor)) {
      if (debug) {
        log.debug(contextClosingDown[0] + "String_Node_Str");
      }
    }
  }
  this.managedContexts.clear();
  nsManager.destroy();
  if (applicationListeners != null) {
    applicationListeners=null;
    try {
      applicationListenersCleaner.destroy();
    }
 catch (    Exception ex) {
      log.warn("String_Node_Str",ex);
    }
  }
  if (multicaster != null) {
    multicaster.removeAllListeners();
    multicaster=null;
  }
  stopTaskExecutor();
  extenderConfiguration.destroy();
}

Fixed version (ground truth):
/** 
 * Shutdown the extender and all bundled managed by it. Shutdown of contexts is in the topological order of the dependency graph formed by the service references.
 */
protected void shutdown(){
synchronized (monitor) {
    if (isClosed)     return;
 else     isClosed=true;
  }
  log.info("String_Node_Str" + bundleContext.getBundle().getSymbolicName() + "String_Node_Str"+ extenderVersion+ "String_Node_Str");
  stopTimer();
  if (contextListener != null) {
    bundleContext.removeBundleListener(contextListener);
    contextListener=null;
  }
  if (nsListener != null) {
    bundleContext.removeBundleListener(nsListener);
    nsListener=null;
  }
  Bundle[] bundles=new Bundle[managedContexts.size()];
  int i=0;
  for (Iterator it=managedContexts.values().iterator(); it.hasNext(); ) {
    ConfigurableOsgiBundleApplicationContext context=(ConfigurableOsgiBundleApplicationContext)it.next();
    bundles[i++]=context.getBundle();
  }
  bundles=shutdownDependencySorter.computeServiceDependencyGraph(bundles);
  boolean debug=log.isDebugEnabled();
  StringBuffer buffer=new StringBuffer();
  if (debug) {
    buffer.append("String_Node_Str");
    for (i=0; i < bundles.length; i++) {
      buffer.append("String_Node_Str" + bundles[i].getSymbolicName() + "String_Node_Str");
    }
    buffer.append("String_Node_Str");
    log.debug(buffer);
  }
  final List taskList=new ArrayList(managedContexts.size());
  final List closedContexts=Collections.synchronizedList(new ArrayList());
  final Object[] contextClosingDown=new Object[1];
  for (i=0; i < bundles.length; i++) {
    Long id=new Long(bundles[i].getBundleId());
    final ConfigurableOsgiBundleApplicationContext context=(ConfigurableOsgiBundleApplicationContext)managedContexts.get(id);
    if (context != null) {
      closedContexts.add(context);
      taskList.add(new Runnable(){
        private final String toString="String_Node_Str" + context.getDisplayName();
        public void run(){
          contextClosingDown[0]=context;
          closedContexts.remove(context);
          closeApplicationContext(context);
        }
        public String toString(){
          return toString;
        }
      }
);
    }
  }
  final Runnable[] tasks=(Runnable[])taskList.toArray(new Runnable[taskList.size()]);
  for (int j=0; j < tasks.length; j++) {
    if (RunnableTimedExecution.execute(tasks[j],extenderConfiguration.getShutdownWaitTime(),shutdownTaskExecutor)) {
      if (debug) {
        log.debug(contextClosingDown[0] + "String_Node_Str");
      }
    }
  }
  this.managedContexts.clear();
  nsManager.destroy();
  if (applicationListeners != null) {
    applicationListeners=null;
    try {
      applicationListenersCleaner.destroy();
    }
 catch (    Exception ex) {
      log.warn("String_Node_Str",ex);
    }
  }
  if (multicaster != null) {
    multicaster.removeAllListeners();
    multicaster=null;
  }
  stopTaskExecutor();
  extenderConfiguration.destroy();
}