Skip to content

Conversation

@NguyenHoangSon96
Copy link

Proposed Changes

  • Our project works with a library called arrow-java, and this library calls OkHttpReadableBuffer.readBytes(ByteBuffer dest) but this method was not implmented for grpc-okhttp so the calls failed. So I implemented this method so our project can work with arrow-java.
  • I have a talk with the team why this method is not implemented Here

Changes

  • Implement OkHttpReadableBuffer.readBytes(ByteBuffer dest).
  • Make readToByteBufferShouldSucceed test runs for OkHttpReadableBuffer.

Additional Information

  • Codecov complains about missing a test for throw new RuntimeException(e), I'm not sure if this line need to be tested.

@NguyenHoangSon96
Copy link
Author

Hi @ejona86 , can you help me reviewing this PR.
This is my first time contribute for this repo, sorry If I did something incorrectly.
I can't add reviewers like other repos, so I tagged you.

Copy link
Member

@shivaspeaks shivaspeaks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see there'd be any harm with your PR.

Should we go with something like this to align and be consistent with the rest of the codebase?

@Override
public void readBytes(ByteBuffer dest) {
  int remaining = dest.remaining();
  try {
    int read = buffer.read(dest);
    if (read < remaining) {
      throw new IndexOutOfBoundsException("EOF trying to read " + remaining + " bytes");
    }
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

@shivaspeaks shivaspeaks requested a review from ejona86 December 22, 2025 10:04
@NguyenHoangSon96
Copy link
Author

Hi @shivaspeaks
Thank you for jumping on this so quickly, and thank you for your fix.
Can I ask how long the new version with this fix will be released?

Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAK. I don't mind the implementation, but the reason for the change is very, very bad.

Arrow is using our internals via reflection. This is not okay. Not only is it accessing internal classes, it is digging into its fields. In no way is that acceptable, and in no way are we going to assist in that.

This is an Arrow bug, and that code should be removed in Arrow.

There's no need to dig into our internals for accessing the ByteBuffer (which is what GetReadableBuffer reports to do). We have zero-copy APIs. They can use HasByteBuffer.getByteBuffer()+InputStream.skip() to loop through the ByteBuffers. If they want to access all the byte buffers simultaneously (as skip() will deallocate the last byte buffer, just like read() does), then they can use InputStream.mark(). If they want to take over ownership of the ByteBuffers, then they can use Detachable.detach().

@ejona86
Copy link
Member

ejona86 commented Dec 22, 2025

Closing in favor of deleting the method. #12580

@ejona86 ejona86 closed this Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants