Program: 113420
Project: 113420
Buggy source:
@Override public DirectoryEntries readDir(UserCredentials userCredentials,String path,int offset,int count,boolean namesOnly) throws IOException, PosixErrorException, AddressToUUIDNotFoundException {
  DirectoryEntries result=null;
  if (count == 0) {
    count=Integer.MAX_VALUE - offset - 1;
  }
  result=metadataCache.getDirEntries(path,offset,count);
  if (result != null) {
    return result;
  }
  DirectoryEntries.Builder dirEntriesBuilder=DirectoryEntries.newBuilder();
  for (int currentOffset=offset; currentOffset < offset + count; currentOffset+=volumeOptions.getReaddirChunkSize()) {
    int limitDirEntriesCount=(currentOffset > offset + count) ? (currentOffset - offset - count) : volumeOptions.getReaddirChunkSize();
    readdirRequest request=readdirRequest.newBuilder().setPath(path).setVolumeName(volumeName).setNamesOnly(namesOnly).setKnownEtag(0).setSeenDirectoryEntriesCount(currentOffset).setLimitDirectoryEntriesCount(limitDirEntriesCount).build();
    result=RPCCaller.<readdirRequest,DirectoryEntries>syncCall(SERVICES.MRC,userCredentials,authBogus,volumeOptions,uuidResolver,mrcUUIDIterator,false,request,new CallGenerator<readdirRequest,DirectoryEntries>(){
      @Override public RPCResponse<DirectoryEntries> executeCall(      InetSocketAddress server,      Auth authHeader,      UserCredentials userCreds,      readdirRequest input) throws IOException {
        return mrcServiceClient.readdir(server,authHeader,userCreds,input);
      }
    }
);
    assert(result != null);
    dirEntriesBuilder.addAllEntries(result.getEntriesList());
    if (dirEntriesBuilder.getEntriesCount() < (currentOffset + volumeOptions.getReaddirChunkSize())) {
      break;
    }
  }
  int minimum=(volumeOptions.getMetadataCacheSize() > dirEntriesBuilder.getEntriesCount()) ? dirEntriesBuilder.getEntriesCount() : volumeOptions.getMetadataCacheSize();
  for (int i=0; i < minimum; i++) {
    if (dirEntriesBuilder.getEntries(i).hasStbuf()) {
      if (dirEntriesBuilder.getEntries(i).getStbuf().getNlink() > 1) {
        metadataCache.invalidate(path);
      }
 else {
        metadataCache.updateStat(Helper.concatenatePath(path,dirEntriesBuilder.getEntries(i).getName()),dirEntriesBuilder.getEntries(i).getStbuf());
      }
    }
  }
  if (!namesOnly && offset == 0 && dirEntriesBuilder.getEntriesCount() < count) {
    metadataCache.updateDirEntries(path,result);
  }
  return dirEntriesBuilder.build();
}

Fixed version (ground truth):
@Override public DirectoryEntries readDir(UserCredentials userCredentials,String path,int offset,int count,boolean namesOnly) throws IOException, PosixErrorException, AddressToUUIDNotFoundException {
  DirectoryEntries result=null;
  if (count == 0) {
    count=Integer.MAX_VALUE - offset - 1;
  }
  result=metadataCache.getDirEntries(path,offset,count);
  if (result != null) {
    return result;
  }
  DirectoryEntries.Builder dirEntriesBuilder=DirectoryEntries.newBuilder();
  for (int currentOffset=offset; currentOffset < offset + count; currentOffset+=volumeOptions.getReaddirChunkSize()) {
    int limitDirEntriesCount=(currentOffset > offset + count) ? (currentOffset - offset - count) : volumeOptions.getReaddirChunkSize();
    readdirRequest request=readdirRequest.newBuilder().setPath(path).setVolumeName(volumeName).setNamesOnly(namesOnly).setKnownEtag(0).setSeenDirectoryEntriesCount(currentOffset).setLimitDirectoryEntriesCount(limitDirEntriesCount).build();
    DirectoryEntries readDirResponse=RPCCaller.<readdirRequest,DirectoryEntries>syncCall(SERVICES.MRC,userCredentials,authBogus,volumeOptions,uuidResolver,mrcUUIDIterator,false,request,new CallGenerator<readdirRequest,DirectoryEntries>(){
      @Override public RPCResponse<DirectoryEntries> executeCall(      InetSocketAddress server,      Auth authHeader,      UserCredentials userCreds,      readdirRequest input) throws IOException {
        return mrcServiceClient.readdir(server,authHeader,userCreds,input);
      }
    }
);
    assert(readDirResponse != null);
    dirEntriesBuilder.addAllEntries(readDirResponse.getEntriesList());
    if (dirEntriesBuilder.getEntriesCount() < (currentOffset + volumeOptions.getReaddirChunkSize())) {
      break;
    }
  }
  int minimum=(volumeOptions.getMetadataCacheSize() > dirEntriesBuilder.getEntriesCount()) ? dirEntriesBuilder.getEntriesCount() : volumeOptions.getMetadataCacheSize();
  for (int i=0; i < minimum; i++) {
    if (dirEntriesBuilder.getEntries(i).hasStbuf()) {
      if (dirEntriesBuilder.getEntries(i).getStbuf().getNlink() > 1) {
        metadataCache.invalidate(path);
      }
 else {
        metadataCache.updateStat(Helper.concatenatePath(path,dirEntriesBuilder.getEntries(i).getName()),dirEntriesBuilder.getEntries(i).getStbuf());
      }
    }
  }
  result=dirEntriesBuilder.build();
  if (!namesOnly && offset == 0 && result.getEntriesCount() < count) {
    metadataCache.updateDirEntries(path,result);
  }
  return result;
}