Program: 89818
Project: 89818
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);
    }
    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) {
    String errMsg="String_Node_Str";
    log.warn(errMsg,e);
    throw new IOFailure(errMsg,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");
  File secPolFile=new File(directory,Constants.SECURITY_POLICY_FILE_NAME);
  try {
    PrintWriter secPrinter=new PrintWriter(secPolFile);
    try {
      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);
      }
      secPrinter.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()) {
        secPrinter.write("String_Node_Str" + "String_Node_Str");
        for (        String dir : dirs) {
          secPrinter.write(ScriptConstants.writeSecurityPolicyDirPermission(changeFileDirPathForSecurity(dir)));
        }
        secPrinter.write("String_Node_Str");
      }
    }
  finally {
      secPrinter.close();
    }
  }
 catch (  IOException e) {
    String errMsg="String_Node_Str";
    log.warn(errMsg,e);
    throw new IOFailure(errMsg,e);
  }
}