Program: 113523
Project: 113523
Buggy source:
@Override public void createSnapshot(String snapName,long parentId,String dirName,boolean recursive) throws DatabaseException {
  try {
    byte[][][] prefixes=null;
    byte[][][] excludedKeys=null;
    FileMetadata snapDir=getMetadata(parentId,dirName);
    if (snapDir.getId() != 1 || !recursive) {
      List<FileMetadata> nestedFiles=new LinkedList<FileMetadata>();
      BabuDBStorageHelper.getNestedFiles(nestedFiles,database,snapDir.getId(),recursive);
      List<byte[]> dirEntryPrefixes=new ArrayList<byte[]>(nestedFiles.size());
      List<byte[]> filePrefixes=new ArrayList<byte[]>(nestedFiles.size());
      List<byte[]> exclPrefixes=new ArrayList<byte[]>(nestedFiles.size());
      if (snapDir.getId() != 1)       filePrefixes.add(ByteBuffer.wrap(new byte[8]).putLong(1).array());
      byte[] idxKey=BabuDBStorageHelper.createFileKey(parentId,dirName,(byte)-1);
      byte[] fileKey=BabuDBStorageHelper.createFilePrefixKey(snapDir.getId());
      dirEntryPrefixes.add(idxKey);
      filePrefixes.add(fileKey);
      idxKey=BabuDBStorageHelper.createFilePrefixKey(snapDir.getId());
      dirEntryPrefixes.add(idxKey);
      for (      FileMetadata file : nestedFiles) {
        BufferBackedFileMetadata f=(BufferBackedFileMetadata)file;
        byte[] key=BabuDBStorageHelper.createFilePrefixKey(file.getId());
        if (file.isDirectory()) {
          if (!recursive) {
            byte[] buf=f.getKeyBuffer(BufferBackedFileMetadata.RC_METADATA);
            byte[] exclKey=new byte[buf.length - 1];
            System.arraycopy(buf,0,exclKey,0,exclKey.length);
            exclPrefixes.add(exclKey);
          }
 else {
            filePrefixes.add(key);
            dirEntryPrefixes.add(key);
          }
        }
 else         filePrefixes.add(key);
      }
      byte[][] dirEntryPrefixesA=dirEntryPrefixes.toArray(new byte[dirEntryPrefixes.size()][]);
      byte[][] filePrefixesA=filePrefixes.toArray(new byte[filePrefixes.size()][]);
      byte[][] exclPrefixesA=exclPrefixes.toArray(new byte[exclPrefixes.size()][]);
      Arrays.sort(dirEntryPrefixesA,DefaultByteRangeComparator.getInstance());
      Arrays.sort(filePrefixesA,DefaultByteRangeComparator.getInstance());
      prefixes=new byte[][][]{dirEntryPrefixesA,filePrefixesA,filePrefixesA,filePrefixesA,null};
      if (!recursive)       excludedKeys=new byte[][][]{exclPrefixesA,exclPrefixesA,exclPrefixesA,exclPrefixesA,null};
    }
    SnapshotConfig snap=new DefaultSnapshotConfig(snapName,ALL_INDICES,prefixes,excludedKeys);
    snapMan.createPersistentSnapshot(database.getName(),snap);
  }
 catch (  BabuDBException exc) {
    if (exc.getErrorCode().equals(ErrorCode.NO_ACCESS))     throw new DatabaseException(ExceptionType.REDIRECT,this.replMan.getMaster());
 else     throw new DatabaseException(exc);
  }
}

Fixed version (ground truth):
@Override public void createSnapshot(String snapName,long parentId,String dirName,boolean recursive) throws DatabaseException {
  try {
    byte[][][] prefixes=null;
    FileMetadata snapDir=getMetadata(parentId,dirName);
    if (snapDir.getId() != 1 || !recursive) {
      List<FileMetadata> nestedFiles=new LinkedList<FileMetadata>();
      BabuDBStorageHelper.getNestedFiles(nestedFiles,database,snapDir.getId(),recursive);
      List<byte[]> dirEntryPrefixes=new ArrayList<byte[]>(nestedFiles.size());
      List<byte[]> filePrefixes=new ArrayList<byte[]>(nestedFiles.size());
      if (snapDir.getId() != 1)       filePrefixes.add(ByteBuffer.wrap(new byte[8]).putLong(1).array());
      byte[] idxKey=BabuDBStorageHelper.createFileKey(parentId,dirName,(byte)-1);
      byte[] fileKey=BabuDBStorageHelper.createFilePrefixKey(snapDir.getId());
      dirEntryPrefixes.add(idxKey);
      filePrefixes.add(fileKey);
      idxKey=BabuDBStorageHelper.createFilePrefixKey(snapDir.getId());
      dirEntryPrefixes.add(idxKey);
      for (      FileMetadata file : nestedFiles) {
        byte[] key=BabuDBStorageHelper.createFilePrefixKey(file.getId());
        if (file.isDirectory()) {
          filePrefixes.add(key);
          dirEntryPrefixes.add(key);
        }
 else         filePrefixes.add(key);
      }
      byte[][] dirEntryPrefixesA=dirEntryPrefixes.toArray(new byte[dirEntryPrefixes.size()][]);
      byte[][] filePrefixesA=filePrefixes.toArray(new byte[filePrefixes.size()][]);
      Arrays.sort(dirEntryPrefixesA,DefaultByteRangeComparator.getInstance());
      Arrays.sort(filePrefixesA,DefaultByteRangeComparator.getInstance());
      prefixes=new byte[][][]{dirEntryPrefixesA,filePrefixesA,filePrefixesA,filePrefixesA,null};
    }
    SnapshotConfig snap=new DefaultSnapshotConfig(snapName,ALL_INDICES,prefixes,null);
    snapMan.createPersistentSnapshot(database.getName(),snap);
  }
 catch (  BabuDBException exc) {
    if (exc.getErrorCode().equals(ErrorCode.NO_ACCESS))     throw new DatabaseException(ExceptionType.REDIRECT,this.replMan.getMaster());
 else     throw new DatabaseException(exc);
  }
}