Program: 47493
Project: 47493
Buggy source:
@Override public void flush() throws IOException {
  if (closed) {
    return;
  }
  super.flush();
  ByteArrayInputStream bis=new ByteArrayInputStream(toByteArray());
  String ext=RepositoryFilenameUtils.getExtension(path);
  String mimeType="String_Node_Str";
  if (ext != null) {
    String tempMimeType=MimeHelper.getMimeTypeFromExtension("String_Node_Str" + ext);
    if (tempMimeType != null) {
      mimeType=tempMimeType;
    }
  }
  final SimpleRepositoryFileData payload=new SimpleRepositoryFileData(bis,charsetName,mimeType);
  if (!flushed) {
    RepositoryFile file=repository.getFile(path);
    RepositoryFile parentFolder=getParent(path);
    String baseFileName=RepositoryFilenameUtils.getBaseName(path);
    String extension=RepositoryFilenameUtils.getExtension(path);
    if (file == null) {
      if (autoCreateDirStructure) {
        ArrayList<String> foldersToCreate=new ArrayList<String>();
        String parentPath=RepositoryFilenameUtils.getFullPathNoEndSeparator(path);
        while ((parentPath != null) && (parentPath.length() > 0 && !path.equals(parentPath)) && (repository.getFile(parentPath) == null)) {
          foldersToCreate.add(RepositoryFilenameUtils.getName(parentPath));
          parentPath=RepositoryFilenameUtils.getFullPathNoEndSeparator(parentPath);
        }
        Collections.reverse(foldersToCreate);
        parentFolder=((parentPath != null) && (parentPath.length() > 0)) ? repository.getFile(parentPath) : repository.getFile("String_Node_Str");
        if (!parentFolder.isFolder()) {
          throw new FileNotFoundException();
        }
        for (        String folderName : foldersToCreate) {
          parentFolder=repository.createFolder(parentFolder.getId(),new RepositoryFile.Builder(folderName).folder(true).build(),null);
        }
      }
 else {
        if (parentFolder == null) {
          throw new FileNotFoundException();
        }
      }
      file=new RepositoryFile.Builder(RepositoryFilenameUtils.getName(path)).versioned(true).build();
      file=repository.createFile(parentFolder.getId(),file,payload,"String_Node_Str" + RepositoryFileOutputStream.class.getName());
      for (      IRepositoryFileOutputStreamListener listener : listeners) {
        listener.fileCreated(path);
      }
    }
 else     if (file.isFolder()) {
      throw new FileNotFoundException(MessageFormat.format("String_Node_Str",file.getPath()));
    }
 else {
      if (autoCreateUniqueFileName) {
        int nameCount=1;
        String newFileName=null;
        while (file != null) {
          nameCount++;
          if ((extension != null) && (extension.length() > 0)) {
            newFileName=baseFileName + "String_Node_Str" + nameCount+ "String_Node_Str"+ extension;
          }
 else {
            newFileName=baseFileName + "String_Node_Str" + nameCount+ "String_Node_Str";
          }
          file=repository.getFile(parentFolder.getPath() + "String_Node_Str" + newFileName);
        }
        file=new RepositoryFile.Builder(newFileName).versioned(true).build();
        file=repository.createFile(parentFolder.getId(),file,payload,"String_Node_Str");
        path=file.getPath();
        for (        IRepositoryFileOutputStreamListener listener : listeners) {
          listener.fileCreated(path);
        }
      }
 else {
        repository.updateFile(file,payload,"String_Node_Str");
      }
    }
  }
 else {
    RepositoryFile file=repository.getFile(path);
    repository.updateFile(file,payload,"String_Node_Str");
  }
  flushed=true;
}

Fixed version (ground truth):
@Override public void flush() throws IOException {
  if (closed) {
    return;
  }
  super.flush();
  ByteArrayInputStream bis=new ByteArrayInputStream(toByteArray());
  String ext=RepositoryFilenameUtils.getExtension(path);
  String mimeType="String_Node_Str";
  if (ext != null) {
    String tempMimeType=MimeHelper.getMimeTypeFromExtension("String_Node_Str" + ext);
    if (tempMimeType != null) {
      mimeType=tempMimeType;
    }
  }
  final SimpleRepositoryFileData payload=new SimpleRepositoryFileData(bis,charsetName,mimeType);
  if (!flushed) {
    RepositoryFile file=repository.getFile(path);
    RepositoryFile parentFolder=getParent(path);
    String baseFileName=RepositoryFilenameUtils.getBaseName(path);
    String extension=RepositoryFilenameUtils.getExtension(path);
    if (file == null) {
      if (autoCreateDirStructure) {
        ArrayList<String> foldersToCreate=new ArrayList<String>();
        String parentPath=RepositoryFilenameUtils.getFullPathNoEndSeparator(path);
        while ((parentPath != null) && (parentPath.length() > 0 && !path.equals(parentPath)) && (repository.getFile(parentPath) == null)) {
          foldersToCreate.add(RepositoryFilenameUtils.getName(parentPath));
          parentPath=RepositoryFilenameUtils.getFullPathNoEndSeparator(parentPath);
        }
        Collections.reverse(foldersToCreate);
        parentFolder=((parentPath != null) && (parentPath.length() > 0)) ? repository.getFile(parentPath) : repository.getFile("String_Node_Str");
        if (!parentFolder.isFolder()) {
          throw new FileNotFoundException();
        }
        for (        String folderName : foldersToCreate) {
          parentFolder=repository.createFolder(parentFolder.getId(),new RepositoryFile.Builder(folderName).folder(true).build(),null);
        }
      }
 else {
        if (parentFolder == null) {
          throw new FileNotFoundException();
        }
      }
      file=new RepositoryFile.Builder(RepositoryFilenameUtils.getName(path)).versioned(true).build();
      file=repository.createFile(parentFolder.getId(),file,payload,"String_Node_Str" + RepositoryFileOutputStream.class.getName());
      for (      IStreamListener listener : listeners) {
        listener.fileCreated(path);
      }
    }
 else     if (file.isFolder()) {
      throw new FileNotFoundException(MessageFormat.format("String_Node_Str",file.getPath()));
    }
 else {
      if (autoCreateUniqueFileName) {
        int nameCount=1;
        String newFileName=null;
        while (file != null) {
          nameCount++;
          if ((extension != null) && (extension.length() > 0)) {
            newFileName=baseFileName + "String_Node_Str" + nameCount+ "String_Node_Str"+ extension;
          }
 else {
            newFileName=baseFileName + "String_Node_Str" + nameCount+ "String_Node_Str";
          }
          file=repository.getFile(parentFolder.getPath() + "String_Node_Str" + newFileName);
        }
        file=new RepositoryFile.Builder(newFileName).versioned(true).build();
        file=repository.createFile(parentFolder.getId(),file,payload,"String_Node_Str");
        path=file.getPath();
        for (        IStreamListener listener : listeners) {
          listener.fileCreated(path);
        }
      }
 else {
        repository.updateFile(file,payload,"String_Node_Str");
      }
    }
  }
 else {
    RepositoryFile file=repository.getFile(path);
    repository.updateFile(file,payload,"String_Node_Str");
  }
  flushed=true;
}