Program: 28721
Project: 28721
Buggy source:
/** 
 * Performs all the domain configurations which includes security, configuration processing, substitution of parameters... etc.
 * @throws DomainException If any exception occurs in configuration.
 */
public void run() throws RepositoryException, DomainException {
  File domainDir=FileUtils.safeGetCanonicalFile(new File(_domainConfig.getRepositoryRoot(),_domainConfig.getDomainName()));
  try {
    if (!domainDir.mkdirs()) {
      throw new RepositoryException(_strings.get("String_Node_Str",domainDir));
    }
  }
 catch (  Exception e) {
    throw new RepositoryException(_strings.get("String_Node_Str",domainDir),e);
  }
  try {
    byte[] buffer=new byte[10000];
    for (Enumeration<JarEntry> entry=_templateJar.entries(); entry.hasMoreElements(); ) {
      JarEntry jarEntry=(JarEntry)entry.nextElement();
      String entryName=jarEntry.getName();
      if (entryName.startsWith(META_DIR_NAME)) {
        continue;
      }
      if (extractedEntries.contains(entryName)) {
        continue;
      }
      if (jarEntry.isDirectory()) {
        File dir=new File(domainDir,jarEntry.getName());
        if (!dir.exists()) {
          if (!dir.mkdir()) {
            _logger.log(Level.WARNING,_strings.get("String_Node_Str",dir.getName()));
          }
        }
        continue;
      }
      InputStream in=null;
      BufferedOutputStream outputStream=null;
      try {
        in=_templateJar.getInputStream(jarEntry);
        outputStream=new BufferedOutputStream(new FileOutputStream(new File(domainDir.getAbsolutePath(),jarEntry.getName())));
        int i=0;
        while ((i=in.read(buffer)) != -1) {
          outputStream.write(buffer,0,i);
        }
      }
  finally {
        if (in != null) {
          try {
            in.close();
          }
 catch (          Exception io) {
          }
        }
        if (outputStream != null) {
          try {
            outputStream.close();
          }
 catch (          Exception io) {
          }
        }
      }
    }
    File configDir=new File(domainDir,DomainConstants.CONFIG_DIR);
    String user=(String)_domainConfig.get(DomainConfig.K_USER);
    String password=(String)_domainConfig.get(DomainConfig.K_PASSWORD);
    String masterPassword=(String)_domainConfig.get(DomainConfig.K_MASTER_PASSWORD);
    Boolean saveMasterPassword=(Boolean)_domainConfig.get(DomainConfig.K_SAVE_MASTER_PASSWORD);
    DomainSecurity domainSecurity=new DomainSecurity();
    domainSecurity.processAdminKeyFile(new File(configDir,DomainConstants.ADMIN_KEY_FILE),user,password);
    try {
      domainSecurity.createSSLCertificateDatabase(configDir,_domainConfig,masterPassword);
    }
 catch (    Exception e) {
      String msg=_strings.getString("String_Node_Str",e.getMessage());
      System.err.println(msg);
      FileOutputStream fos=null;
      try {
        File keystoreFile=new File(configDir,DomainConstants.KEYSTORE_FILE);
        fos=new FileOutputStream(keystoreFile);
        fos.write(keystoreBytes);
      }
 catch (      Exception ex) {
        getLogger().log(Level.SEVERE,UNHANDLED_EXCEPTION,ex);
      }
 finally {
        if (fos != null)         fos.close();
      }
    }
    domainSecurity.changeMasterPasswordInMasterPasswordFile(new File(configDir,DomainConstants.MASTERPASSWORD_FILE),masterPassword,saveMasterPassword);
    domainSecurity.createPasswordAliasKeystore(new File(configDir,DomainConstants.DOMAIN_PASSWORD_FILE),masterPassword);
    if (_domainTempalte.hasStringsubs()) {
      StringSubstitutor substitutor=_domainTempalte.getStringSubs();
      Map<String,String> lookUpMap=SubstitutableTokens.getSubstitutableTokens(_domainConfig);
      substitutor.setAttributePreprocessor(new AttributePreprocessorImpl(lookUpMap));
      substitutor.substituteAll();
    }
    try {
      domainSecurity.changeMode("String_Node_Str",configDir);
    }
 catch (    Exception e) {
      throw new DomainException(_strings.get("String_Node_Str"),e);
    }
    DomainInfoManager domainInfoManager=new DomainInfoManager();
    domainInfoManager.process(_domainTempalte,domainDir);
  }
 catch (  DomainException de) {
    FileUtils.liquidate(domainDir);
    throw de;
  }
catch (  Exception ex) {
    FileUtils.liquidate(domainDir);
    throw new DomainException(ex);
  }
}

Fixed version (ground truth):
/** 
 * Performs all the domain configurations which includes security, configuration processing, substitution of parameters... etc.
 * @throws DomainException If any exception occurs in configuration.
 */
public void run() throws RepositoryException, DomainException {
  File domainDir=FileUtils.safeGetCanonicalFile(new File(_domainConfig.getRepositoryRoot(),_domainConfig.getDomainName()));
  createDirectory(domainDir);
  try {
    byte[] buffer=new byte[10000];
    for (Enumeration<JarEntry> entry=_templateJar.entries(); entry.hasMoreElements(); ) {
      JarEntry jarEntry=(JarEntry)entry.nextElement();
      String entryName=jarEntry.getName();
      if (entryName.startsWith(META_DIR_NAME)) {
        continue;
      }
      if (extractedEntries.contains(entryName)) {
        continue;
      }
      if (jarEntry.isDirectory()) {
        File dir=new File(domainDir,jarEntry.getName());
        if (!dir.exists()) {
          if (!dir.mkdir()) {
            _logger.log(Level.WARNING,_strings.get("String_Node_Str",dir.getName()));
          }
        }
        continue;
      }
      InputStream in=null;
      BufferedOutputStream outputStream=null;
      try {
        in=_templateJar.getInputStream(jarEntry);
        outputStream=new BufferedOutputStream(new FileOutputStream(new File(domainDir.getAbsolutePath(),jarEntry.getName())));
        int i=0;
        while ((i=in.read(buffer)) != -1) {
          outputStream.write(buffer,0,i);
        }
      }
  finally {
        if (in != null) {
          try {
            in.close();
          }
 catch (          Exception io) {
          }
        }
        if (outputStream != null) {
          try {
            outputStream.close();
          }
 catch (          Exception io) {
          }
        }
      }
    }
    File configDir=new File(domainDir,DomainConstants.CONFIG_DIR);
    String user=(String)_domainConfig.get(DomainConfig.K_USER);
    String password=(String)_domainConfig.get(DomainConfig.K_PASSWORD);
    String masterPassword=(String)_domainConfig.get(DomainConfig.K_MASTER_PASSWORD);
    Boolean saveMasterPassword=(Boolean)_domainConfig.get(DomainConfig.K_SAVE_MASTER_PASSWORD);
    DomainSecurity domainSecurity=new DomainSecurity();
    domainSecurity.processAdminKeyFile(new File(configDir,DomainConstants.ADMIN_KEY_FILE),user,password);
    try {
      domainSecurity.createSSLCertificateDatabase(configDir,_domainConfig,masterPassword);
    }
 catch (    Exception e) {
      String msg=_strings.getString("String_Node_Str",e.getMessage());
      System.err.println(msg);
      FileOutputStream fos=null;
      try {
        File keystoreFile=new File(configDir,DomainConstants.KEYSTORE_FILE);
        fos=new FileOutputStream(keystoreFile);
        fos.write(keystoreBytes);
      }
 catch (      Exception ex) {
        getLogger().log(Level.SEVERE,UNHANDLED_EXCEPTION,ex);
      }
 finally {
        if (fos != null)         fos.close();
      }
    }
    domainSecurity.changeMasterPasswordInMasterPasswordFile(new File(configDir,DomainConstants.MASTERPASSWORD_FILE),masterPassword,saveMasterPassword);
    domainSecurity.createPasswordAliasKeystore(new File(configDir,DomainConstants.DOMAIN_PASSWORD_FILE),masterPassword);
    if (_domainTempalte.hasStringsubs()) {
      StringSubstitutor substitutor=_domainTempalte.getStringSubs();
      Map<String,String> lookUpMap=SubstitutableTokens.getSubstitutableTokens(_domainConfig);
      substitutor.setAttributePreprocessor(new AttributePreprocessorImpl(lookUpMap));
      substitutor.substituteAll();
    }
    try {
      domainSecurity.changeMode("String_Node_Str",configDir);
    }
 catch (    Exception e) {
      throw new DomainException(_strings.get("String_Node_Str"),e);
    }
    DomainInfoManager domainInfoManager=new DomainInfoManager();
    domainInfoManager.process(_domainTempalte,domainDir);
  }
 catch (  DomainException de) {
    FileUtils.liquidate(domainDir);
    throw de;
  }
catch (  Exception ex) {
    FileUtils.liquidate(domainDir);
    throw new DomainException(ex);
  }
}