Program: 13257
Project: 13257
Buggy source:
@Override public void run(){
  try {
    final int BUFFER_SIZE=4 * 4096;
    long fileSize=file.length();
    if (fileSize == 0) {
      logger.warn("String_Node_Str",request.shardId().index().name(),request.shardId().id(),file.getName());
    }
    FileInputStream fileStream=new FileInputStream(file);
    String filePath=file.getAbsolutePath();
    String relPath=filePath.substring(baseDir.length(),filePath.length());
    byte[] buf=new byte[BUFFER_SIZE];
    int bytesRead=fileStream.read(buf,0,BUFFER_SIZE);
    long bytesReadTotal=0;
    BytesArray content=new BytesArray(buf,0,bytesRead);
    BlobRecoveryStartTransferRequest startTransferRequest=new BlobRecoveryStartTransferRequest(request.recoveryId(),relPath,content,fileSize);
    if (bytesRead > 0) {
      bytesReadTotal+=bytesRead;
      logger.trace("String_Node_Str",request.shardId().index().name(),request.shardId().id(),request.targetNode().getName(),relPath,fileSize);
      transportService.submitRequest(request.targetNode(),BlobRecoveryTarget.Actions.START_TRANSFER,startTransferRequest,TransportRequestOptions.options(),EmptyTransportResponseHandler.INSTANCE_SAME).txGet();
      boolean isLast=false;
      boolean sentChunks=false;
      while ((bytesRead=fileStream.read(buf,0,BUFFER_SIZE)) > 0) {
        sentChunks=true;
        bytesReadTotal+=bytesRead;
        if (shard.state() == IndexShardState.CLOSED) {
          throw new IndexShardClosedException(shard.shardId());
        }
        if (bytesReadTotal == fileSize) {
          isLast=true;
        }
        content=new BytesArray(buf,0,bytesRead);
        transportService.submitRequest(request.targetNode(),BlobRecoveryTarget.Actions.TRANSFER_CHUNK,new BlobRecoveryChunkRequest(request.recoveryId(),startTransferRequest.transferId(),content,isLast),TransportRequestOptions.options(),EmptyTransportResponseHandler.INSTANCE_SAME).txGet();
      }
      if (!isLast && sentChunks) {
        logger.error("String_Node_Str",relPath);
        transportService.submitRequest(request.targetNode(),BlobRecoveryTarget.Actions.TRANSFER_CHUNK,new BlobRecoveryChunkRequest(request.recoveryId(),startTransferRequest.transferId(),BytesArray.EMPTY,true),TransportRequestOptions.options(),EmptyTransportResponseHandler.INSTANCE_SAME).txGet();
      }
    }
    logger.trace("String_Node_Str",request.shardId().index().name(),request.shardId().id(),file.getName(),request.targetNode().getName());
  }
 catch (  IOException ex) {
    logger.error("String_Node_Str",ex);
    lastException.set(ex);
  }
 finally {
    latch.countDown();
  }
}

Fixed version (ground truth):
@Override public void run(){
  try {
    final int BUFFER_SIZE=4 * 4096;
    long fileSize=file.length();
    if (fileSize == 0) {
      logger.warn("String_Node_Str",request.shardId().index().name(),request.shardId().id(),file.getName());
    }
    try (FileInputStream fileStream=new FileInputStream(file)){
      String filePath=file.getAbsolutePath();
      String relPath=filePath.substring(baseDir.length(),filePath.length());
      byte[] buf=new byte[BUFFER_SIZE];
      int bytesRead=fileStream.read(buf,0,BUFFER_SIZE);
      long bytesReadTotal=0;
      BytesArray content=new BytesArray(buf,0,bytesRead);
      BlobRecoveryStartTransferRequest startTransferRequest=new BlobRecoveryStartTransferRequest(request.recoveryId(),relPath,content,fileSize);
      if (bytesRead > 0) {
        bytesReadTotal+=bytesRead;
        logger.trace("String_Node_Str",request.shardId().index().name(),request.shardId().id(),request.targetNode().getName(),relPath,fileSize);
        transportService.submitRequest(request.targetNode(),BlobRecoveryTarget.Actions.START_TRANSFER,startTransferRequest,TransportRequestOptions.options(),EmptyTransportResponseHandler.INSTANCE_SAME).txGet();
        boolean isLast=false;
        boolean sentChunks=false;
        while ((bytesRead=fileStream.read(buf,0,BUFFER_SIZE)) > 0) {
          sentChunks=true;
          bytesReadTotal+=bytesRead;
          if (shard.state() == IndexShardState.CLOSED) {
            throw new IndexShardClosedException(shard.shardId());
          }
          if (bytesReadTotal == fileSize) {
            isLast=true;
          }
          content=new BytesArray(buf,0,bytesRead);
          transportService.submitRequest(request.targetNode(),BlobRecoveryTarget.Actions.TRANSFER_CHUNK,new BlobRecoveryChunkRequest(request.recoveryId(),startTransferRequest.transferId(),content,isLast),TransportRequestOptions.options(),EmptyTransportResponseHandler.INSTANCE_SAME).txGet();
        }
        if (!isLast && sentChunks) {
          logger.error("String_Node_Str",relPath);
          transportService.submitRequest(request.targetNode(),BlobRecoveryTarget.Actions.TRANSFER_CHUNK,new BlobRecoveryChunkRequest(request.recoveryId(),startTransferRequest.transferId(),BytesArray.EMPTY,true),TransportRequestOptions.options(),EmptyTransportResponseHandler.INSTANCE_SAME).txGet();
        }
      }
      logger.trace("String_Node_Str",request.shardId().index().name(),request.shardId().id(),file.getName(),request.targetNode().getName());
    }
   }
 catch (  IOException ex) {
    logger.error("String_Node_Str",ex);
    lastException.set(ex);
  }
 finally {
    latch.countDown();
  }
}