Skip to content

Commit b82fabd

Browse files
author
Dmytro Borysov
committed
Replace IllegalStateException with EOFException in readRawVarint32
- Replace unchecked IllegalStateException with checked EOFException and IOException - Enables graceful handling of corrupted disk-buffered data Fixes #2684
1 parent 88b5548 commit b82fabd

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

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

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();
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();
4445
}
4546
if ((b & 0x80) == 0) {
4647
return result;
4748
}
4849
}
49-
throw new IllegalStateException();
50+
throw new IOException();
5051
}
5152

5253
/**

0 commit comments

Comments
 (0)