Program: 89858
Project: 89858
Buggy source:
/** 
 * Copy inherited securityPolicyFile to local directory.
 * @param directory The local directory for this machine
 */
protected void createSecurityPolicyFile(File directory){
  ArgumentNotValid.checkNotNull(directory,"String_Node_Str");
  try {
    File secPolFile=new File(directory,Constants.SECURITY_POLICY_FILE_NAME);
    FileWriter secfw=new FileWriter(secPolFile);
    String prop=FileUtils.readFile(inheritedSecurityPolicyFile);
    String monitorRole=settings.getLeafValue(Constants.SETTINGS_MONITOR_JMX_NAME_LEAF);
    if (monitorRole != null) {
      prop=prop.replace(Constants.SECURITY_JMX_PRINCIPAL_NAME_TAG,monitorRole);
    }
    String ctd=settings.getLeafValue(Constants.SETTINGS_TEMPDIR_LEAF);
    if (ctd != null) {
      prop=prop.replace(Constants.SECURITY_COMMON_TEMP_DIR_TAG,ctd);
    }
    secfw.write(prop);
    List<String> dirs=new ArrayList<String>();
    for (    Application app : applications) {
      String[] tmpDirs=app.getSettingsValues(Constants.SETTINGS_BITARCHIVE_BASEFILEDIR_LEAF);
      if (tmpDirs != null && tmpDirs.length > 0) {
        for (        String st : tmpDirs) {
          dirs.add(st);
        }
      }
    }
    if (!dirs.isEmpty()) {
      secfw.write("String_Node_Str" + "String_Node_Str");
      for (      String dir : dirs) {
        secfw.write(ScriptConstants.writeSecurityPolicyDirPermission(changeFileDirPathForSecurity(dir)));
      }
      secfw.write("String_Node_Str");
    }
    secfw.close();
  }
 catch (  IOException e) {
    log.warn("String_Node_Str" + e);
  }
}

Fixed version (ground truth):
/** 
 * Copy inherited securityPolicyFile to local directory.
 * @param directory The local directory for this machine
 */
protected void createSecurityPolicyFile(File directory){
  ArgumentNotValid.checkNotNull(directory,"String_Node_Str");
  try {
    File secPolFile=new File(directory,Constants.SECURITY_POLICY_FILE_NAME);
    FileWriter secfw=new FileWriter(secPolFile);
    String prop=FileUtils.readFile(inheritedSecurityPolicyFile);
    String monitorRole=settings.getLeafValue(Constants.SETTINGS_MONITOR_JMX_NAME_LEAF);
    if (monitorRole != null) {
      prop=prop.replace(Constants.SECURITY_JMX_PRINCIPAL_NAME_TAG,monitorRole);
    }
    String ctd=settings.getLeafValue(Constants.SETTINGS_TEMPDIR_LEAF);
    if (ctd != null) {
      prop=prop.replace(Constants.SECURITY_COMMON_TEMP_DIR_TAG,ctd);
    }
    try {
      secfw.write(prop);
      List<String> dirs=new ArrayList<String>();
      for (      Application app : applications) {
        String[] tmpDirs=app.getSettingsValues(Constants.SETTINGS_BITARCHIVE_BASEFILEDIR_LEAF);
        if (tmpDirs != null && tmpDirs.length > 0) {
          for (          String st : tmpDirs) {
            dirs.add(st);
          }
        }
      }
      if (!dirs.isEmpty()) {
        secfw.write("String_Node_Str" + "String_Node_Str");
        for (        String dir : dirs) {
          secfw.write(ScriptConstants.writeSecurityPolicyDirPermission(changeFileDirPathForSecurity(dir)));
        }
        secfw.write("String_Node_Str");
      }
    }
  finally {
      if (secfw != null) {
        secfw.close();
      }
    }
  }
 catch (  IOException e) {
    log.warn("String_Node_Str" + e);
  }
}