Program: 89855
Project: 89855
Buggy source:
/** 
 * Creates the start scripts for all the applications. The application should only be started, if it is not running already. The script starts by finding all running processes of the application. If any processes are found, a new application should not be started. Otherwise start the application. The start_app.sh should have the following structure: - echo Starting linux application: app - cd path - #!/bin/bash - PIDS = $(ps -wwfe | grep fullapp | grep -v grep | grep  path\settings_app.xml | awk "{print \\$2}") - if [ -n "$PIDS" ]; then -     echo Application already running. - else -     export CLASSPATH = cp:$CLASSPATH; -     JAVA - fi where: path = the path to the install directory. fullapp = the full name application with java path. app = the name of the application. cp = the classpaths for the application. JAVA = the command to run the java application.
 * @param directory The directory for this machine (use global variable?).
 */
@Override protected void createApplicationStartScripts(File directory){
  ArgumentNotValid.checkNotNull(directory,"String_Node_Str");
  for (  Application app : applications) {
    File appStartScript=new File(directory,Constants.SCRIPT_NAME_LOCAL_START + app.getIdentification() + scriptExtension);
    try {
      PrintWriter appPrint=new PrintWriter(appStartScript);
      try {
        appPrint.println(ScriptConstants.ECHO_START_LINUX_APP + Constants.COLON + Constants.SPACE+ app.getIdentification());
        appPrint.println(ScriptConstants.CD + Constants.SPACE + app.installPathLinux());
        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.ECHO_APP_ALREADY_RUNNING);
        appPrint.println(ScriptConstants.ELSE);
        appPrint.println(ScriptConstants.EXPORT_CLASSPATH + osGetClassPath(app) + ScriptConstants.VALUE_OF_CLASSPATH+ Constants.SEMICOLON);
        appPrint.println(ScriptConstants.MULTI_SPACE_2 + ScriptConstants.JAVA + Constants.SPACE+ app.getMachineParameters().writeJavaOptions()+ Constants.SPACE+ Constants.DASH+ ScriptConstants.OPTION_SETTINGS+ getConfDirPath()+ Constants.PREFIX_SETTINGS+ app.getIdentification()+ Constants.EXTENSION_XML_FILES+ Constants.SPACE+ Constants.DASH+ ScriptConstants.OPTION_LOG_COMPLETE+ Constants.SPACE+ Constants.DASH+ ScriptConstants.OPTION_LOG_CONFIG+ getConfDirPath()+ Constants.LOG_PREFIX+ app.getIdentification()+ Constants.EXTENSION_LOG_PROPERTY_FILES+ Constants.SPACE+ Constants.DASH+ ScriptConstants.OPTION_SECURITY_MANAGER+ Constants.SPACE+ Constants.DASH+ ScriptConstants.OPTION_SECIRITY_POLICY+ getConfDirPath()+ Constants.SECURITY_POLICY_FILE_NAME+ Constants.SPACE+ app.getTotalName()+ Constants.SPACE+ ScriptConstants.LINUX_DEV_NULL+ Constants.SPACE+ Constants.SCRIPT_NAME_LOCAL_START+ app.getIdentification()+ Constants.EXTENSION_LOG_FILES+ Constants.SPACE+ ScriptConstants.LINUX_ERROR_MESSAGE_TO_1);
        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 start scripts for all the applications. The application should only be started, if it is not running already. The script starts by finding all running processes of the application. If any processes are found, a new application should not be started. Otherwise start the application. The start_app.sh should have the following structure: - echo Starting linux application: app - cd path - #!/bin/bash - PIDS = $(ps -wwfe | grep fullapp | grep -v grep | grep  path\settings_app.xml | awk "{print \\$2}") - if [ -n "$PIDS" ]; then -     echo Application already running. - else -     export CLASSPATH = cp:$CLASSPATH; -     JAVA - fi where: path = the path to the install directory. fullapp = the full name application with java path. app = the name of the application. cp = the classpaths for the application. JAVA = the command to run the java application.
 * @param directory The directory for this machine (use global variable?).
 */
@Override protected void createApplicationStartScripts(File directory){
  ArgumentNotValid.checkNotNull(directory,"String_Node_Str");
  for (  Application app : applications) {
    File appStartScript=new File(directory,Constants.SCRIPT_NAME_LOCAL_START + app.getIdentification() + scriptExtension);
    try {
      PrintWriter appPrint=new PrintWriter(appStartScript);
      try {
        appPrint.println(ScriptConstants.ECHO_START_LINUX_APP + Constants.COLON + Constants.SPACE+ app.getIdentification());
        appPrint.println(ScriptConstants.CD + Constants.SPACE + app.installPathLinux());
        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.ECHO_APP_ALREADY_RUNNING);
        appPrint.println(ScriptConstants.ELSE);
        appPrint.println(ScriptConstants.EXPORT_CLASSPATH + osGetClassPath(app) + ScriptConstants.VALUE_OF_CLASSPATH+ Constants.SEMICOLON);
        appPrint.println(ScriptConstants.MULTI_SPACE_2 + ScriptConstants.JAVA + Constants.SPACE+ app.getMachineParameters().writeJavaOptions()+ Constants.SPACE+ Constants.DASH+ ScriptConstants.OPTION_SETTINGS+ getConfDirPath()+ Constants.PREFIX_SETTINGS+ app.getIdentification()+ Constants.EXTENSION_XML_FILES+ Constants.SPACE+ Constants.DASH+ ScriptConstants.OPTION_LOG_COMPLETE+ Constants.SPACE+ Constants.DASH+ ScriptConstants.OPTION_LOG_CONFIG+ getConfDirPath()+ Constants.LOG_PREFIX+ app.getIdentification()+ Constants.EXTENSION_LOG_PROPERTY_FILES+ Constants.SPACE+ Constants.DASH+ ScriptConstants.OPTION_SECURITY_MANAGER+ Constants.SPACE+ Constants.DASH+ ScriptConstants.OPTION_SECIRITY_POLICY+ getConfDirPath()+ Constants.SECURITY_POLICY_FILE_NAME+ Constants.SPACE+ app.getTotalName()+ Constants.SPACE+ ScriptConstants.LINUX_DEV_NULL+ Constants.SPACE+ Constants.SCRIPT_NAME_LOCAL_START+ app.getIdentification()+ Constants.EXTENSION_LOG_FILES+ Constants.SPACE+ ScriptConstants.LINUX_ERROR_MESSAGE_TO_1);
        appPrint.println(ScriptConstants.FI);
      }
  finally {
        appPrint.close();
      }
    }
 catch (    IOException e) {
      String msg="String_Node_Str" + e;
      log.trace(msg);
      throw new IOFailure(msg);
    }
catch (    Throwable e) {
      String msg="String_Node_Str" + e;
      log.trace(msg);
      System.out.println(msg);
    }
  }
}