Program: 40079
Project: 40079
Buggy source:
/** 
 * A convenience method to create a temporary repository and open a connection to it. When the connection is closed all underlying objects (EmbeddedGraphDB and LocalRepositoryManager) will be closed as well. The temporary repository is created in a unique temporary directory that will be deleted when the program terminates.
 * @param ruleset ruleset to use for the repository, e.g. owl-horst-optimized
 * @return a RepositoryConnection to a new temporary repository
 * @throws IOException
 * @throws RepositoryException
 * @throws RDFParseException
 * @throws GraphUtilException
 * @throws RepositoryConfigException
 * @throws RDFHandlerException
 */
public static RepositoryConnection openConnectionToTemporaryRepository(String ruleset) throws IOException, RepositoryException, RDFParseException, RepositoryConfigException, RDFHandlerException {
  File baseDir=FileUtil.createTempDir("String_Node_Str");
  baseDir.deleteOnExit();
  final EmbeddedGraphDB embeddedGraphDB=new EmbeddedGraphDB(baseDir.getAbsolutePath());
  embeddedGraphDB.createRepository("String_Node_Str",null,Collections.singletonMap("String_Node_Str",ruleset));
  Repository repository=embeddedGraphDB.getRepository("String_Node_Str");
  RepositoryConnection connection=repository.getConnection();
  return new RepositoryConnectionWrapper(repository,connection){
    @Override public void close() throws RepositoryException {
      super.close();
      try {
        embeddedGraphDB.close();
      }
 catch (      IOException e) {
        throw new RepositoryException(e);
      }
    }
  }
;
}

Fixed version (ground truth):
/** 
 * A convenience method to create a temporary repository and open a connection to it. When the connection is closed all underlying objects (EmbeddedGraphDB and LocalRepositoryManager) will be closed as well. The temporary repository is created in a unique temporary directory that will be deleted when the program terminates.
 * @param ruleset ruleset to use for the repository, e.g. owl-horst-optimized
 * @return a RepositoryConnection to a new temporary repository
 * @throws IOException
 * @throws RepositoryException
 * @throws RDFParseException
 * @throws GraphUtilException
 * @throws RepositoryConfigException
 * @throws RDFHandlerException
 */
public static RepositoryConnection openConnectionToTemporaryRepository(String ruleset) throws IOException {
  File baseDir=FileUtil.createTempDir("String_Node_Str");
  baseDir.deleteOnExit();
  try {
    singleton=new EmbeddedGraphDB(baseDir.getAbsolutePath());
    singleton.createRepository("String_Node_Str",null,Collections.singletonMap("String_Node_Str",ruleset));
    Repository repository=singleton.getRepository("String_Node_Str");
    RepositoryConnection connection=repository.getConnection();
    return new RepositoryConnectionWrapper(repository,connection){
      @Override public void close() throws RepositoryException {
        super.close();
        try {
          if (singleton != null) {
            singleton.close();
          }
        }
 catch (        IOException e) {
          throw new RepositoryException(e);
        }
      }
    }
;
  }
 catch (  RepositoryException e) {
    singleton.close();
    singleton=null;
    throw e;
  }
}