Program: 89823
Project: 89823
Buggy source:
/** 
 * Creates the kill scripts for all the applications. The script starts by finding all running processes of the application. If it finds any processes, it kills them.  The kill_app.sh should have the following structure: - echo Killing linux application. - #!/bin/bash - PIDS = $(ps -wwfe | grep fullapp | grep -v grep | grep  path\settings_app.xml | awk "{print \\$2}") - if [ -n "$PIDS" ]; then -     kill -9 $PIDS; - fi Also, if a heritrix process is started, the following is added: - PIDS = $(ps -wwfe | grep heritrix | grep -v grep | grep  path\settings_app.xml | awk "{print \\$2}") - if [ -n "$PIDS" ]; then -     kill -9 $PIDS; - fi where: path = the path to the ./conf directory. fullapp = the full application name with class path. app = the id of the application (name + instanceId). heritrix = the heritrix class path.
 * @param directory The directory for this machine (use global variable?).
 */
@Override protected void createApplicationKillScripts(File directory){
  ArgumentNotValid.checkNotNull(directory,"String_Node_Str");
  for (  Application app : applications) {
    File appKillScript=new File(directory,Constants.SCRIPT_NAME_LOCAL_KILL + app.getIdentification() + scriptExtension);
    try {
      PrintWriter appPrint=new PrintWriter(appKillScript);
      try {
        appPrint.println(ScriptConstants.ECHO_KILL_LINUX_APPLICATION + Constants.COLON + Constants.SPACE+ app.getIdentification());
        appPrint.println(ScriptConstants.BIN_BASH_COMMENT);
        appPrint.println(ScriptConstants.getLinuxPIDS(app.getTotalName(),getConfDirPath(),app.getIdentification()));
        appPrint.println(ScriptConstants.LINUX_IF_N_EXIST + Constants.SPACE + Constants.QUOTE_MARK+ ScriptConstants.PIDS+ Constants.QUOTE_MARK+ Constants.SPACE+ ScriptConstants.LINUX_N_THEN);
        appPrint.println(ScriptConstants.KILL_9_PIDS + Constants.SEMICOLON);
        appPrint.println(ScriptConstants.FI);
        String[] heritrixJmxPort=app.getSettingsValues(Constants.SETTINGS_HARVEST_HETRIX_JMX_PORT);
        if (heritrixJmxPort != null) {
          if (heritrixJmxPort.length > 1) {
            log.trace(heritrixJmxPort.length + "String_Node_Str" + "String_Node_Str");
          }
          appPrint.println(ScriptConstants.getLinuxPIDS(Heritrix.class.getName(),getConfDirPath(),app.getIdentification()));
          appPrint.println(ScriptConstants.LINUX_IF_N_EXIST + Constants.SPACE + Constants.QUOTE_MARK+ ScriptConstants.PIDS+ Constants.QUOTE_MARK+ Constants.SPACE+ ScriptConstants.LINUX_N_THEN);
          appPrint.println(ScriptConstants.KILL_9_PIDS);
          appPrint.println(ScriptConstants.FI);
        }
      }
  finally {
        appPrint.close();
      }
    }
 catch (    IOException e) {
      String msg="String_Node_Str" + e;
      log.trace(msg);
      throw new IOFailure(msg);
    }
catch (    Exception e) {
      String msg="String_Node_Str" + e;
      log.trace(msg);
      System.out.println(msg);
    }
  }
}

Fixed version (ground truth):
/** 
 * Creates the kill scripts for all the applications. The script starts by finding all running processes of the application. If it finds any processes, it kills them.  The kill_app.sh should have the following structure: - echo Killing linux application. - #!/bin/bash - PIDS = $(ps -wwfe | grep fullapp | grep -v grep | grep  path\settings_app.xml | awk "{print \\$2}") - if [ -n "$PIDS" ]; then -     kill -9 $PIDS; - fi Also, if a heritrix process is started, the following is added: - PIDS = $(ps -wwfe | grep heritrix | grep -v grep | grep  path\settings_app.xml | awk "{print \\$2}") - if [ -n "$PIDS" ]; then -     kill -9 $PIDS; - fi where: path = the path to the ./conf directory. fullapp = the full application name with class path. app = the id of the application (name + instanceId). heritrix = the heritrix class path.
 * @param directory The directory for this machine (use global variable?).
 */
@Override protected void createApplicationKillScripts(File directory){
  ArgumentNotValid.checkNotNull(directory,"String_Node_Str");
  for (  Application app : applications) {
    File appKillScript=new File(directory,Constants.SCRIPT_NAME_LOCAL_KILL + app.getIdentification() + scriptExtension);
    try {
      PrintWriter appPrint=new PrintWriter(appKillScript);
      try {
        appPrint.println(ScriptConstants.ECHO_KILL_LINUX_APPLICATION + Constants.COLON + Constants.SPACE+ app.getIdentification());
        appPrint.println(ScriptConstants.BIN_BASH_COMMENT);
        appPrint.println(ScriptConstants.getLinuxPIDS(app.getTotalName(),getConfDirPath(),app.getIdentification()));
        appPrint.println(ScriptConstants.LINUX_IF_N_EXIST + Constants.SPACE + Constants.QUOTE_MARK+ ScriptConstants.PIDS+ Constants.QUOTE_MARK+ Constants.SPACE+ ScriptConstants.LINUX_N_THEN);
        appPrint.println(ScriptConstants.KILL_9_PIDS + Constants.SEMICOLON);
        appPrint.println(ScriptConstants.FI);
        String[] heritrixJmxPort=app.getSettingsValues(Constants.SETTINGS_HARVEST_HETRIX_JMX_PORT);
        if (heritrixJmxPort != null && heritrixJmxPort.length > 0) {
          if (heritrixJmxPort.length > 1) {
            log.trace(heritrixJmxPort.length + "String_Node_Str" + "String_Node_Str");
          }
          appPrint.println(ScriptConstants.getLinuxPIDS(Heritrix.class.getName(),getConfDirPath(),app.getIdentification()));
          appPrint.println(ScriptConstants.LINUX_IF_N_EXIST + Constants.SPACE + Constants.QUOTE_MARK+ ScriptConstants.PIDS+ Constants.QUOTE_MARK+ Constants.SPACE+ ScriptConstants.LINUX_N_THEN);
          appPrint.println(ScriptConstants.KILL_9_PIDS);
          appPrint.println(ScriptConstants.FI);
        }
      }
  finally {
        appPrint.close();
      }
    }
 catch (    IOException e) {
      String msg="String_Node_Str" + e;
      log.trace(msg);
      throw new IOFailure(msg);
    }
catch (    Exception e) {
      String msg="String_Node_Str" + e;
      log.trace(msg);
      System.out.println(msg);
    }
  }
}