Program: 84485
Project: 84485
Buggy source:
/** 
 * Runs through the advice and extension points and removes from api.<br/> <code>skipOverStartedProperty</code> should only be true when openmrs is stopping modules because it is shutting down. When normally stopping a module, use   {@link #stopModule(Module)}(or leave value as false). This property controls whether the globalproperty is set for startup/shutdown. <br/> Also calls module's   {@link Activator#shutdown()}
 * @param mod module to stop
 * @param skipOverStartedProperty true if we don't want to set &lt;moduleid&gt;.started to false
 * @param isFailedStartup true if this is being called as a cleanup because of a failed modulestartup
 * @return list of dependent modules that were stopped because this module was stopped. Thiswill never be null.
 */
@SuppressWarnings("String_Node_Str") public static List<Module> stopModule(Module mod,boolean skipOverStartedProperty,boolean isFailedStartup) throws ModuleMustStartException {
  List<Module> dependentModulesStopped=new Vector<Module>();
  if (mod != null) {
    try {
      if (mod.getModuleActivator() != null)       mod.getModuleActivator().willStop();
    }
 catch (    Throwable t) {
      log.warn("String_Node_Str",t);
    }
    String moduleId=mod.getModuleId();
    if (!isFailedStartup && mod.isMandatory()) {
      throw new MandatoryModuleException(moduleId);
    }
    if (!isFailedStartup && ModuleConstants.CORE_MODULES.containsKey(moduleId)) {
      throw new OpenmrsCoreModuleException(moduleId);
    }
    String modulePackage=mod.getPackageName();
    List<Module> startedModulesCopy=new ArrayList<Module>();
    startedModulesCopy.addAll(getStartedModules());
    for (    Module dependentModule : startedModulesCopy) {
      if (!dependentModule.equals(mod) && dependentModule.getRequiredModules().contains(modulePackage)) {
        dependentModulesStopped.add(dependentModule);
        dependentModulesStopped.addAll(stopModule(dependentModule,skipOverStartedProperty,isFailedStartup));
      }
    }
    getStartedModulesMap().remove(moduleId);
    if (skipOverStartedProperty == false && !Context.isRefreshingContext()) {
      saveGlobalProperty(moduleId + "String_Node_Str","String_Node_Str",getGlobalPropertyStartedDescription(moduleId));
    }
    if (getModuleClassLoaderMap().containsKey(mod)) {
      log.debug("String_Node_Str");
      try {
        for (        AdvicePoint advice : mod.getAdvicePoints()) {
          Class cls=null;
          try {
            cls=Context.loadClass(advice.getPoint());
            Object aopObject=advice.getClassInstance();
            if (Advisor.class.isInstance(aopObject)) {
              log.debug("String_Node_Str" + aopObject.getClass());
              Context.removeAdvisor(cls,(Advisor)aopObject);
            }
 else {
              log.debug("String_Node_Str" + aopObject.getClass());
              Context.removeAdvice(cls,(Advice)aopObject);
            }
          }
 catch (          Throwable t) {
            log.warn("String_Node_Str" + advice.getPoint(),t);
          }
        }
      }
 catch (      Throwable t) {
        log.warn("String_Node_Str" + moduleId,t);
      }
      try {
        for (        Extension ext : mod.getExtensions()) {
          String extId=ext.getExtensionId();
          try {
            List<Extension> tmpExtensions=getExtensions(extId);
            if (tmpExtensions == null)             tmpExtensions=new Vector<Extension>();
            tmpExtensions.remove(ext);
            getExtensionMap().put(extId,tmpExtensions);
          }
 catch (          Exception exterror) {
            log.warn("String_Node_Str" + ext,exterror);
          }
        }
      }
 catch (      Throwable t) {
        log.warn("String_Node_Str" + moduleId,t);
      }
    }
    try {
      if (mod.getModuleActivator() != null)       mod.getModuleActivator().stopped();
 else       mod.getActivator().shutdown();
    }
 catch (    Throwable t) {
      log.warn("String_Node_Str",t);
    }
    ModuleClassLoader cl=removeClassLoader(mod);
    if (cl != null) {
      cl.dispose();
      cl=null;
      File folder=OpenmrsClassLoader.getLibCacheFolder();
      File tmpModuleDir=new File(folder,moduleId);
      try {
        OpenmrsUtil.deleteDirectory(tmpModuleDir);
      }
 catch (      IOException e) {
        log.warn("String_Node_Str" + moduleId);
      }
    }
  }
  return dependentModulesStopped;
}

Fixed version (ground truth):
/** 
 * Runs through the advice and extension points and removes from api.<br/> <code>skipOverStartedProperty</code> should only be true when openmrs is stopping modules because it is shutting down. When normally stopping a module, use   {@link #stopModule(Module)}(or leave value as false). This property controls whether the globalproperty is set for startup/shutdown. <br/> Also calls module's   {@link Activator#shutdown()}
 * @param mod module to stop
 * @param skipOverStartedProperty true if we don't want to set &lt;moduleid&gt;.started to false
 * @param isFailedStartup true if this is being called as a cleanup because of a failed modulestartup
 * @return list of dependent modules that were stopped because this module was stopped. Thiswill never be null.
 */
@SuppressWarnings("String_Node_Str") public static List<Module> stopModule(Module mod,boolean skipOverStartedProperty,boolean isFailedStartup) throws ModuleMustStartException {
  List<Module> dependentModulesStopped=new Vector<Module>();
  if (mod != null) {
    try {
      if (mod.getModuleActivator() != null)       mod.getModuleActivator().willStop();
    }
 catch (    Throwable t) {
      log.warn("String_Node_Str",t);
    }
    String moduleId=mod.getModuleId();
    if (!isFailedStartup && mod.isMandatory()) {
      throw new MandatoryModuleException(moduleId);
    }
    if (!isFailedStartup && ModuleConstants.CORE_MODULES.containsKey(moduleId)) {
      throw new OpenmrsCoreModuleException(moduleId);
    }
    String modulePackage=mod.getPackageName();
    List<Module> startedModulesCopy=new ArrayList<Module>();
    startedModulesCopy.addAll(getStartedModules());
    for (    Module dependentModule : startedModulesCopy) {
      if (!dependentModule.equals(mod) && dependentModule.getRequiredModules().contains(modulePackage)) {
        dependentModulesStopped.add(dependentModule);
        dependentModulesStopped.addAll(stopModule(dependentModule,skipOverStartedProperty,isFailedStartup));
      }
    }
    getStartedModulesMap().remove(moduleId);
    if (skipOverStartedProperty == false && !Context.isRefreshingContext()) {
      saveGlobalProperty(moduleId + "String_Node_Str","String_Node_Str",getGlobalPropertyStartedDescription(moduleId));
    }
    if (getModuleClassLoaderMap().containsKey(mod)) {
      log.debug("String_Node_Str");
      try {
        for (        AdvicePoint advice : mod.getAdvicePoints()) {
          Class cls=null;
          try {
            cls=Context.loadClass(advice.getPoint());
            Object aopObject=advice.getClassInstance();
            if (Advisor.class.isInstance(aopObject)) {
              log.debug("String_Node_Str" + aopObject.getClass());
              Context.removeAdvisor(cls,(Advisor)aopObject);
            }
 else {
              log.debug("String_Node_Str" + aopObject.getClass());
              Context.removeAdvice(cls,(Advice)aopObject);
            }
          }
 catch (          Throwable t) {
            log.warn("String_Node_Str" + advice.getPoint(),t);
          }
        }
      }
 catch (      Throwable t) {
        log.warn("String_Node_Str" + moduleId,t);
      }
      try {
        for (        Extension ext : mod.getExtensions()) {
          String extId=ext.getExtensionId();
          try {
            List<Extension> tmpExtensions=getExtensions(extId);
            if (tmpExtensions == null)             tmpExtensions=new Vector<Extension>();
            tmpExtensions.remove(ext);
            getExtensionMap().put(extId,tmpExtensions);
          }
 catch (          Exception exterror) {
            log.warn("String_Node_Str" + ext,exterror);
          }
        }
      }
 catch (      Throwable t) {
        log.warn("String_Node_Str" + moduleId,t);
      }
    }
    try {
      if (mod.getModuleActivator() != null)       mod.getModuleActivator().stopped();
 else       mod.getActivator().shutdown();
    }
 catch (    Throwable t) {
      log.warn("String_Node_Str",t);
    }
    mod.getExtensions().clear();
    mod.setActivator(null);
    mod.setModuleActivator(null);
    mod.disposeAdvicePointsClassInstance();
    ModuleClassLoader cl=removeClassLoader(mod);
    if (cl != null) {
      cl.dispose();
      cl=null;
      File folder=OpenmrsClassLoader.getLibCacheFolder();
      File tmpModuleDir=new File(folder,moduleId);
      try {
        OpenmrsUtil.deleteDirectory(tmpModuleDir);
      }
 catch (      IOException e) {
        log.warn("String_Node_Str" + moduleId);
      }
    }
  }
  return dependentModulesStopped;
}