Program: 47578
Project: 47578
Buggy source:
/** 
 * Adds the metadata domain to the repository
 * @param domain the domain to add
 * @throws Exception indicates an error saving the metadata domain to the repository
 */
public void addDomainToRepository(final Domain domain) throws Exception {
  final String domainId=domain.getId();
  final String methodCall="String_Node_Str" + domainId + "String_Node_Str";
  logger.debug(methodCall);
  final String domainPath=jcrMetadataInfo.getMetadataFolderPath() + RepositoryFile.SEPARATOR + domainId;
  InputStream inputStream=null;
  try {
    logger.debug(methodCall + "String_Node_Str");
    final String xmi=getXmiParser().generateXmi(domain);
    inputStream=new ByteArrayInputStream(xmi.getBytes(LocaleHelper.getSystemEncoding()));
    logger.debug(methodCall + "String_Node_Str");
    final String domainFile=domainPath + RepositoryFile.SEPARATOR + jcrMetadataInfo.getMetadataFilename();
    IRepositoryFileData repoFileData=new SimpleRepositoryFileData(inputStream,characterEncoding,mimeType);
    final RepositoryFile metadataFile=repositoryUtils.getFile(domainFile,repoFileData,true,true,"String_Node_Str");
    logger.debug(methodCall + "String_Node_Str");
  }
  finally {
    if (inputStream != null) {
      inputStream.close();
    }
  }
  logger.debug(methodCall + "String_Node_Str" + domainPath);
  final Properties mappingProperties=getMetadataMappingFile();
  mappingProperties.setProperty(domainId,domainPath);
  writeMappingPropertiesFiles(mappingProperties);
  dumpMappings();
}

Fixed version (ground truth):
/** 
 * Adds the metadata domain to the repository
 * @param domain the domain to add
 * @throws Exception indicates an error saving the metadata domain to the repository
 */
public void addDomainToRepository(final Domain domain) throws Exception {
  final String domainId=domain.getId();
  final String methodCall="String_Node_Str" + domainId + "String_Node_Str";
  logger.debug(methodCall);
  final String domainPath=jcrMetadataInfo.getMetadataFolderPath() + RepositoryFile.SEPARATOR + domainId;
  final String domainFile=domainPath + RepositoryFile.SEPARATOR + jcrMetadataInfo.getMetadataFilename();
  InputStream inputStream=null;
  try {
    logger.debug(methodCall + "String_Node_Str");
    final String xmi=getXmiParser().generateXmi(domain);
    inputStream=new ByteArrayInputStream(xmi.getBytes(LocaleHelper.getSystemEncoding()));
    logger.debug(methodCall + "String_Node_Str");
    IRepositoryFileData repoFileData=new SimpleRepositoryFileData(inputStream,characterEncoding,mimeType);
    final RepositoryFile metadataFile=repositoryUtils.getFile(domainFile,null,false,false,null);
    if (metadataFile == null) {
      repositoryUtils.getFile(domainFile,repoFileData,true,true,"String_Node_Str");
    }
 else {
      repository.updateFile(metadataFile,repoFileData,"String_Node_Str");
    }
    logger.debug(methodCall + "String_Node_Str");
  }
  finally {
    if (inputStream != null) {
      inputStream.close();
    }
  }
  logger.debug(methodCall + "String_Node_Str" + domainPath);
  final Properties mappingProperties=getMetadataMappingFile();
  mappingProperties.setProperty(domainId,domainFile);
  writeMappingPropertiesFiles(mappingProperties);
}