From 172286bc46097d1866bb50c1436dd1de1a566b59 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Mon, 22 Mar 2021 16:58:25 -0700 Subject: [PATCH] okhttp: Fix okio 2.x API incompatibility okio 2.x is ABI compatible with 1.x but not API compatible. This hasn't been a problem as users use binaries from Maven Central so the ABI compatibility is the important part. However, when building with Bazel the API compatibily is the important part. Tested with okio 2.10.0 Fixes #8004 --- .../main/java/io/grpc/okhttp/OkHttpReadableBuffer.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/okhttp/src/main/java/io/grpc/okhttp/OkHttpReadableBuffer.java b/okhttp/src/main/java/io/grpc/okhttp/OkHttpReadableBuffer.java index 821f2e5fd84..136ee8954a2 100644 --- a/okhttp/src/main/java/io/grpc/okhttp/OkHttpReadableBuffer.java +++ b/okhttp/src/main/java/io/grpc/okhttp/OkHttpReadableBuffer.java @@ -40,9 +40,16 @@ public int readableBytes() { @Override public int readUnsignedByte() { - return buffer.readByte() & 0x000000FF; + try { + fakeEofExceptionMethod(); // Okio 2.x can throw EOFException from readByte() + return buffer.readByte() & 0x000000FF; + } catch (EOFException e) { + throw new IndexOutOfBoundsException(e.getMessage()); + } } + private void fakeEofExceptionMethod() throws EOFException {} + @Override public void skipBytes(int length) { try {