Program: 28185
Project: 28185
Buggy source:
/** 
 * Undeploys an application from specified targets.
 * @param targets the targets from which to undeploy the app
 * @param moduleID the app
 * @param undeploymentOptions options to control the undeployment
 * @return DFProgressObject for monitoring progress and querying status
 */
public DFProgressObject undeploy(Target[] targets,String moduleID,Map undeploymentOptions){
  ensureConnected();
  targets=prepareTargets(targets);
  ProgressObjectImpl po=new ProgressObjectImpl(targets);
  List<TargetModuleIDImpl> targetModuleIDList=new ArrayList<TargetModuleIDImpl>();
  try {
    if (!isTargetsMatched(moduleID,targets)) {
      po.setupForAbnormalExit(localStrings.getLocalString("String_Node_Str","String_Node_Str",moduleID,"String_Node_Str"),domain);
    }
    Map deleteAppRefOptions=new HashMap();
    if (undeploymentOptions.get(DFDeploymentProperties.CASCADE) != null) {
      deleteAppRefOptions.put(DFDeploymentProperties.CASCADE,undeploymentOptions.get(DFDeploymentProperties.CASCADE));
    }
    for (int i=0; i < targets.length - 1; i++) {
      deleteAppRefOptions.put(DFDeploymentProperties.TARGET,targets[i].getName());
      DFCommandRunner commandRunner=getDFCommandRunner("String_Node_Str",deleteAppRefOptions,new String[]{moduleID});
      DFDeploymentStatus ds=commandRunner.run();
      DFDeploymentStatus mainStatus=ds.getMainStatus();
      if (!po.checkStatusAndAddStage((TargetImpl)targets[i],localStrings.getLocalString("String_Node_Str","String_Node_Str",targets[i].getName()),mainStatus)) {
        return po;
      }
 else {
        TargetModuleIDImpl targetModuleID=new TargetModuleIDImpl((TargetImpl)targets[i],moduleID);
        targetModuleIDList.add(targetModuleID);
      }
    }
    Target lastTarget=targets[targets.length - 1];
    undeploymentOptions.put(DFDeploymentProperties.TARGET,lastTarget.getName());
    DFCommandRunner commandRunner2=getDFCommandRunner("String_Node_Str",undeploymentOptions,new String[]{moduleID});
    DFDeploymentStatus ds2=commandRunner2.run();
    DFDeploymentStatus mainStatus2=ds2.getMainStatus();
    if (!po.checkStatusAndAddStage((TargetImpl)lastTarget,localStrings.getLocalString("String_Node_Str","String_Node_Str",lastTarget.getName()),mainStatus2)) {
      return po;
    }
    TargetModuleIDImpl targetModuleID=new TargetModuleIDImpl((TargetImpl)lastTarget,moduleID);
    targetModuleIDList.add(targetModuleID);
    TargetModuleIDImpl[] targetModuleIDs=new TargetModuleIDImpl[targetModuleIDList.size()];
    targetModuleIDs=(TargetModuleIDImpl[])targetModuleIDList.toArray(targetModuleIDs);
    po.setupForNormalExit(localStrings.getLocalString("String_Node_Str","String_Node_Str",moduleID),(TargetImpl)targets[0],targetModuleIDs);
    return po;
  }
 catch (  Throwable ioex) {
    po.setupForAbnormalExit(localStrings.getLocalString("String_Node_Str","String_Node_Str",ioex.toString()),(TargetImpl)targets[0]);
    return po;
  }
}

Fixed version (ground truth):
/** 
 * Undeploys an application from specified targets.
 * @param targets the targets from which to undeploy the app
 * @param moduleID the app
 * @param undeploymentOptions options to control the undeployment
 * @return DFProgressObject for monitoring progress and querying status
 */
public DFProgressObject undeploy(Target[] targets,String moduleID,Map undeploymentOptions){
  ensureConnected();
  targets=prepareTargets(targets);
  ProgressObjectImpl po=new ProgressObjectImpl(targets);
  po.setCommand(CommandType.UNDEPLOY,null);
  List<TargetModuleIDImpl> targetModuleIDList=new ArrayList<TargetModuleIDImpl>();
  try {
    if (!isTargetsMatched(moduleID,targets)) {
      po.setupForAbnormalExit(localStrings.getLocalString("String_Node_Str","String_Node_Str",moduleID,"String_Node_Str"),domain);
    }
    Map deleteAppRefOptions=new HashMap();
    if (undeploymentOptions.get(DFDeploymentProperties.CASCADE) != null) {
      deleteAppRefOptions.put(DFDeploymentProperties.CASCADE,undeploymentOptions.get(DFDeploymentProperties.CASCADE));
    }
    for (int i=0; i < targets.length - 1; i++) {
      deleteAppRefOptions.put(DFDeploymentProperties.TARGET,targets[i].getName());
      DFCommandRunner commandRunner=getDFCommandRunner("String_Node_Str",deleteAppRefOptions,new String[]{moduleID});
      DFDeploymentStatus ds=commandRunner.run();
      DFDeploymentStatus mainStatus=ds.getMainStatus();
      if (!po.checkStatusAndAddStage((TargetImpl)targets[i],localStrings.getLocalString("String_Node_Str","String_Node_Str",targets[i].getName()),mainStatus)) {
        return po;
      }
 else {
        TargetModuleIDImpl targetModuleID=new TargetModuleIDImpl((TargetImpl)targets[i],moduleID);
        targetModuleIDList.add(targetModuleID);
      }
    }
    Target lastTarget=targets[targets.length - 1];
    undeploymentOptions.put(DFDeploymentProperties.TARGET,lastTarget.getName());
    DFCommandRunner commandRunner2=getDFCommandRunner("String_Node_Str",undeploymentOptions,new String[]{moduleID});
    DFDeploymentStatus ds2=commandRunner2.run();
    DFDeploymentStatus mainStatus2=ds2.getMainStatus();
    if (!po.checkStatusAndAddStage((TargetImpl)lastTarget,localStrings.getLocalString("String_Node_Str","String_Node_Str",lastTarget.getName()),mainStatus2)) {
      return po;
    }
    TargetModuleIDImpl targetModuleID=new TargetModuleIDImpl((TargetImpl)lastTarget,moduleID);
    targetModuleIDList.add(targetModuleID);
    TargetModuleIDImpl[] targetModuleIDs=new TargetModuleIDImpl[targetModuleIDList.size()];
    targetModuleIDs=(TargetModuleIDImpl[])targetModuleIDList.toArray(targetModuleIDs);
    po.setupForNormalExit(localStrings.getLocalString("String_Node_Str","String_Node_Str",moduleID),(TargetImpl)targets[0],targetModuleIDs);
    return po;
  }
 catch (  Throwable ioex) {
    po.setupForAbnormalExit(localStrings.getLocalString("String_Node_Str","String_Node_Str",ioex.toString()),(TargetImpl)targets[0]);
    return po;
  }
}