Skip to content

Commit 0834da3

Browse files
authored
Replace IllegalStateException with EOFException in readRawVarint32 (#2687)
1 parent 552d3fa commit 0834da3

File tree

1 file changed

+4
-3
lines changed
  • disk-buffering/src/main/java/io/opentelemetry/contrib/disk/buffering/internal/utils

1 file changed

+4
-3
lines changed

disk-buffering/src/main/java/io/opentelemetry/contrib/disk/buffering/internal/utils/ProtobufTools.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.contrib.disk.buffering.internal.utils;
77

88
import com.squareup.wire.ProtoAdapter;
9+
import java.io.EOFException;
910
import java.io.IOException;
1011
import java.io.InputStream;
1112
import java.io.OutputStream;
@@ -29,7 +30,7 @@ public static int readRawVarint32(int firstByte, InputStream input) throws IOExc
2930
for (; offset < 32; offset += 7) {
3031
int b = input.read();
3132
if (b == -1) {
32-
throw new IllegalStateException();
33+
throw new EOFException("Unexpected end-of-stream while reading a varint32. Offset < 32");
3334
}
3435
result |= (b & 0x7f) << offset;
3536
if ((b & 0x80) == 0) {
@@ -40,13 +41,13 @@ public static int readRawVarint32(int firstByte, InputStream input) throws IOExc
4041
for (; offset < 64; offset += 7) {
4142
int b = input.read();
4243
if (b == -1) {
43-
throw new IllegalStateException();
44+
throw new EOFException("Unexpected end-of-stream while reading a varint32. Offset < 64");
4445
}
4546
if ((b & 0x80) == 0) {
4647
return result;
4748
}
4849
}
49-
throw new IllegalStateException();
50+
throw new IOException("Malformed/overlong varint32");
5051
}
5152

5253
/**

0 commit comments

Comments
 (0)