Program: 89820
Project: 89820
Buggy source:
/** 
 * Creates the kill scripts for all the applications. Two script files are created: kill_app.bat and kill_ps_app.bat.  kill_ps_app.bat kills the process of the application. kill_app.bat runs kill_ps_app.bat if the application is running. run_app tells if the application is running. It is deleted during kill. The kill_app.bat should have the following structure: - ECHO Killing application : app - CD "path" - IF EXIST run_app GOTO KILL - GOTO NOKILL -  - :KILL - cmdrun kill_ps_app.bat - DEL run_app - GOTO DONE -  - :NOKILL - ECHO Cannot kill application. Already running. - - :DONE  where: app = application name. path = the path to the ./conf directory. cmdrun = the windows command to run other batch programs. The kill_ps_app.bat is empty upon creation. When the application is started, the command to kill the process of  he application is written to this file as the only content. It will look something like this: - taskkill /F /PID id where: id = the process identification number of the running application.  TODO kill the potential heritrix process, created by a harvester. Just like on Linux/Unix.  If we in the future add the possibility of running heritrix on Windows.
 * @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) {
    String id=app.getIdentification();
    String killPsName=Constants.SCRIPT_KILL_PS + id + scriptExtension;
    File appKillScript=new File(directory,Constants.SCRIPT_NAME_LOCAL_KILL + id + scriptExtension);
    File appKillPsScript=new File(directory,killPsName);
    try {
      PrintWriter appPrint=new PrintWriter(appKillScript);
      PrintWriter appPsPrint=new PrintWriter(appKillPsScript);
      try {
        appPsPrint.println("String_Node_Str");
        String tmpRunApp=Constants.FILE_TEMPORARY_RUN_WINDOWS_NAME + id;
        appPrint.println(ScriptConstants.ECHO_KILL_WINDOWS_APPLICATION + Constants.COLON + Constants.SPACE+ id);
        appPrint.println(ScriptConstants.CD + Constants.SPACE + Constants.QUOTE_MARK+ app.installPathWindows()+ Constants.CONF_DIR_WINDOWS+ Constants.QUOTE_MARK);
        appPrint.println(ScriptConstants.IF + Constants.SPACE + ScriptConstants.EXIST+ Constants.SPACE+ tmpRunApp+ Constants.SPACE+ ScriptConstants.GOTO+ Constants.SPACE+ ScriptConstants.LABEL_KILL);
        appPrint.println(ScriptConstants.GOTO + Constants.SPACE + ScriptConstants.LABEL_NOKILL);
        appPrint.println();
        appPrint.println(Constants.COLON + ScriptConstants.LABEL_KILL);
        appPrint.println(ScriptConstants.OPERATING_SYSTEM_WINDOWS_RUN_BATCH_FILE + Constants.QUOTE_MARK + killPsName+ Constants.QUOTE_MARK);
        appPrint.println(ScriptConstants.DEL + Constants.SPACE + tmpRunApp);
        appPrint.println(ScriptConstants.GOTO + Constants.SPACE + ScriptConstants.LABEL_DONE);
        appPrint.println();
        appPrint.println(Constants.COLON + ScriptConstants.LABEL_NOKILL);
        appPrint.println(ScriptConstants.ECHO_CANNOT_KILL_APP);
        appPrint.println();
        appPrint.println(Constants.COLON + ScriptConstants.LABEL_DONE);
      }
  finally {
        if (appPrint != null) {
          appPrint.close();
        }
        if (appPsPrint != null) {
          appPsPrint.close();
        }
      }
    }
 catch (    IOException e) {
      String msg="String_Node_Str" + "String_Node_Str" + app.getIdentification() + "String_Node_Str"+ name+ "String_Node_Str";
      log.trace(msg,e);
      throw new IOFailure(msg,e);
    }
  }
}

Fixed version (ground truth):
/** 
 * Creates the kill scripts for all the applications. Two script files are created: kill_app.bat and kill_ps_app.bat.  kill_ps_app.bat kills the process of the application. kill_app.bat runs kill_ps_app.bat if the application is running. run_app tells if the application is running. It is deleted during kill. The kill_app.bat should have the following structure: - ECHO Killing application : app - CD "path" - IF EXIST run_app GOTO KILL - GOTO NOKILL -  - :KILL - cmdrun kill_ps_app.bat - DEL run_app - GOTO DONE -  - :NOKILL - ECHO Cannot kill application. Already running. - - :DONE  where: app = application name. path = the path to the ./conf directory. cmdrun = the windows command to run other batch programs. The kill_ps_app.bat is empty upon creation. When the application is started, the command to kill the process of  he application is written to this file as the only content. It will look something like this: - taskkill /F /PID id where: id = the process identification number of the running application.  TODO kill the potential heritrix process, created by a harvester. Just like on Linux/Unix.  If we in the future add the possibility of running heritrix on Windows.
 * @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) {
    String id=app.getIdentification();
    String killPsName=Constants.SCRIPT_KILL_PS + id + scriptExtension;
    File appKillScript=new File(directory,Constants.SCRIPT_NAME_LOCAL_KILL + id + scriptExtension);
    File appKillPsScript=new File(directory,killPsName);
    try {
      PrintWriter appPrint=new PrintWriter(appKillScript);
      try {
        String tmpRunApp=Constants.FILE_TEMPORARY_RUN_WINDOWS_NAME + id;
        appPrint.println(ScriptConstants.ECHO_KILL_WINDOWS_APPLICATION + Constants.COLON + Constants.SPACE+ id);
        appPrint.println(ScriptConstants.CD + Constants.SPACE + Constants.QUOTE_MARK+ app.installPathWindows()+ Constants.CONF_DIR_WINDOWS+ Constants.QUOTE_MARK);
        appPrint.println(ScriptConstants.IF + Constants.SPACE + ScriptConstants.EXIST+ Constants.SPACE+ tmpRunApp+ Constants.SPACE+ ScriptConstants.GOTO+ Constants.SPACE+ ScriptConstants.LABEL_KILL);
        appPrint.println(ScriptConstants.GOTO + Constants.SPACE + ScriptConstants.LABEL_NOKILL);
        appPrint.println();
        appPrint.println(Constants.COLON + ScriptConstants.LABEL_KILL);
        appPrint.println(ScriptConstants.OPERATING_SYSTEM_WINDOWS_RUN_BATCH_FILE + Constants.QUOTE_MARK + killPsName+ Constants.QUOTE_MARK);
        appPrint.println(ScriptConstants.DEL + Constants.SPACE + tmpRunApp);
        appPrint.println(ScriptConstants.GOTO + Constants.SPACE + ScriptConstants.LABEL_DONE);
        appPrint.println();
        appPrint.println(Constants.COLON + ScriptConstants.LABEL_NOKILL);
        appPrint.println(ScriptConstants.ECHO_CANNOT_KILL_APP);
        appPrint.println();
        appPrint.println(Constants.COLON + ScriptConstants.LABEL_DONE);
      }
  finally {
        appPrint.close();
      }
      PrintWriter appPsPrint=new PrintWriter(appKillPsScript);
      try {
        appPsPrint.println("String_Node_Str");
      }
  finally {
        appPsPrint.close();
      }
    }
 catch (    IOException e) {
      String msg="String_Node_Str" + "String_Node_Str" + app.getIdentification() + "String_Node_Str"+ name+ "String_Node_Str";
      log.trace(msg,e);
      throw new IOFailure(msg,e);
    }
  }
}