Program: 90037
Project: 90037
Buggy source:
/** 
 * This method does the following: Retrieves the path to the jmxremote.access and jmxremote.password files. Moves these files, if they are different from standard. Makes the jmxremote.access and jmxremote.password files readonly.
 * @return The commands for handling the jmxremote files.
 */
@Override protected String getJMXremoteFilesCommand(){
  String accessFilePath;
  String passwordFilePath;
  String[] options;
  options=settings.getLeafValues(Constants.SETTINGS_COMMON_JMX_ACCESSFILE);
  if (options == null || options.length < 0) {
    accessFilePath=Constants.JMX_ACCESS_FILE_PATH_DEFAULT;
  }
 else {
    accessFilePath=options[0];
    if (options.length > 1) {
      log.debug(Constants.MSG_WARN_TOO_MANY_JMXREMOTE_FILE_PATHS);
    }
  }
  options=settings.getLeafValues(Constants.SETTINGS_COMMON_JMX_PASSWORDFILE);
  if (options == null || options.length < 0) {
    passwordFilePath=Constants.JMX_PASSWORD_FILE_PATH_DEFAULT;
  }
 else {
    passwordFilePath=options[0];
    if (options.length > 1) {
      log.debug(Constants.MSG_WARN_TOO_MANY_JMXREMOTE_FILE_PATHS);
    }
  }
  StringBuilder res=new StringBuilder();
  res.append(ScriptConstants.ECHO_MAKE_PASSWORD_FILES);
  res.append(Constants.NEWLINE);
  if (accessFilePath != Constants.JMX_ACCESS_FILE_PATH_DEFAULT) {
    res.append(ScriptConstants.SSH + Constants.SPACE);
    res.append(machineUserLogin());
    res.append(Constants.SPACE + Constants.QUOTE_MARK);
    res.append(ScriptConstants.MV);
    res.append(Constants.SPACE);
    res.append(getInstallDirPath());
    res.append(Constants.SLASH);
    res.append(Constants.JMX_ACCESS_FILE_PATH_DEFAULT);
    res.append(Constants.SPACE);
    res.append(getInstallDirPath());
    res.append(Constants.SLASH);
    res.append(accessFilePath);
    res.append(Constants.QUOTE_MARK);
    res.append(Constants.NEWLINE);
  }
  if (passwordFilePath != Constants.JMX_PASSWORD_FILE_PATH_DEFAULT) {
    res.append(ScriptConstants.SSH + Constants.SPACE);
    res.append(machineUserLogin());
    res.append(Constants.SPACE + Constants.QUOTE_MARK);
    res.append(ScriptConstants.MV);
    res.append(Constants.SPACE);
    res.append(getInstallDirPath());
    res.append(Constants.SLASH);
    res.append(Constants.JMX_PASSWORD_FILE_PATH_DEFAULT);
    res.append(Constants.SPACE);
    res.append(getInstallDirPath());
    res.append(Constants.SLASH);
    res.append(passwordFilePath);
    res.append(Constants.QUOTE_MARK);
    res.append(Constants.NEWLINE);
  }
  res.append(ScriptConstants.SSH + Constants.SPACE);
  res.append(machineUserLogin());
  res.append(Constants.SPACE + Constants.QUOTE_MARK + ScriptConstants.LINUX_USER_400+ Constants.SPACE);
  res.append(getInstallDirPath());
  res.append(Constants.SLASH);
  res.append(passwordFilePath);
  res.append(Constants.QUOTE_MARK);
  res.append(Constants.NEWLINE);
  res.append(ScriptConstants.SSH + Constants.SPACE);
  res.append(machineUserLogin());
  res.append(Constants.SPACE + Constants.QUOTE_MARK + ScriptConstants.LINUX_USER_400+ Constants.SPACE);
  res.append(getInstallDirPath());
  res.append(Constants.SLASH);
  res.append(accessFilePath);
  res.append(Constants.QUOTE_MARK);
  res.append(Constants.NEWLINE);
  return res.toString();
}

Fixed version (ground truth):
/** 
 * This method does the following: Retrieves the path to the jmxremote.access and jmxremote.password files. Moves these files, if they are different from standard. Makes the jmxremote.access and jmxremote.password files readonly.
 * @return The commands for handling the jmxremote files.
 */
@Override protected String getJMXremoteFilesCommand(){
  String accessFilePath;
  String passwordFilePath;
  String[] options;
  options=settings.getLeafValues(Constants.SETTINGS_COMMON_JMX_ACCESSFILE);
  if (options == null || options.length < 0) {
    accessFilePath=Constants.JMX_ACCESS_FILE_PATH_DEFAULT;
  }
 else {
    accessFilePath=options[0];
    if (options.length > 1) {
      log.debug(Constants.MSG_WARN_TOO_MANY_JMXREMOTE_FILE_PATHS);
    }
  }
  options=settings.getLeafValues(Constants.SETTINGS_COMMON_JMX_PASSWORDFILE);
  if (options == null || options.length < 0) {
    passwordFilePath=Constants.JMX_PASSWORD_FILE_PATH_DEFAULT;
  }
 else {
    passwordFilePath=options[0];
    if (options.length > 1) {
      log.debug(Constants.MSG_WARN_TOO_MANY_JMXREMOTE_FILE_PATHS);
    }
  }
  StringBuilder res=new StringBuilder();
  res.append(ScriptConstants.ECHO_MAKE_PASSWORD_FILES);
  res.append(Constants.NEWLINE);
  if (!accessFilePath.equals(Constants.JMX_ACCESS_FILE_PATH_DEFAULT)) {
    res.append(ScriptConstants.SSH + Constants.SPACE);
    res.append(machineUserLogin());
    res.append(Constants.SPACE + Constants.QUOTE_MARK);
    res.append(ScriptConstants.MV);
    res.append(Constants.SPACE);
    res.append(getInstallDirPath());
    res.append(Constants.SLASH);
    res.append(Constants.JMX_ACCESS_FILE_PATH_DEFAULT);
    res.append(Constants.SPACE);
    res.append(getInstallDirPath());
    res.append(Constants.SLASH);
    res.append(accessFilePath);
    res.append(Constants.QUOTE_MARK);
    res.append(Constants.NEWLINE);
  }
  if (!passwordFilePath.equals(Constants.JMX_PASSWORD_FILE_PATH_DEFAULT)) {
    res.append(ScriptConstants.SSH + Constants.SPACE);
    res.append(machineUserLogin());
    res.append(Constants.SPACE + Constants.QUOTE_MARK);
    res.append(ScriptConstants.MV);
    res.append(Constants.SPACE);
    res.append(getInstallDirPath());
    res.append(Constants.SLASH);
    res.append(Constants.JMX_PASSWORD_FILE_PATH_DEFAULT);
    res.append(Constants.SPACE);
    res.append(getInstallDirPath());
    res.append(Constants.SLASH);
    res.append(passwordFilePath);
    res.append(Constants.QUOTE_MARK);
    res.append(Constants.NEWLINE);
  }
  res.append(ScriptConstants.SSH + Constants.SPACE);
  res.append(machineUserLogin());
  res.append(Constants.SPACE + Constants.QUOTE_MARK + ScriptConstants.LINUX_USER_400+ Constants.SPACE);
  res.append(getInstallDirPath());
  res.append(Constants.SLASH);
  res.append(passwordFilePath);
  res.append(Constants.QUOTE_MARK);
  res.append(Constants.NEWLINE);
  res.append(ScriptConstants.SSH + Constants.SPACE);
  res.append(machineUserLogin());
  res.append(Constants.SPACE + Constants.QUOTE_MARK + ScriptConstants.LINUX_USER_400+ Constants.SPACE);
  res.append(getInstallDirPath());
  res.append(Constants.SLASH);
  res.append(accessFilePath);
  res.append(Constants.QUOTE_MARK);
  res.append(Constants.NEWLINE);
  return res.toString();
}