Huang-404-Q opened a new pull request, #24073:
URL: https://github.com/apache/kafka/pull/24073
`ChunkedBytesStream` extends `FilterInputStream` and reads through an
intermediate buffer, but it inherits `markSupported()` from the wrapped stream.
When that stream supports marking, `markSupported()` returns `true` here too,
and `reset()` only resets the source stream — the intermediate buffer keeps its
position, so reads after `reset()` return data from the wrong offset:
```java
ChunkedBytesStream stream = new ChunkedBytesStream(
new ByteArrayInputStream(new byte[]{0,...,9}),
BufferSupplier.NO_CACHING, 4, false);
stream.markSupported(); // true, although the class javadoc says
false
stream.read(); // 0
stream.read(); // 1
stream.reset();
stream.read(); // 2, expected 0
```
Silent wrong data is worse than an exception, so the class now reports that
it does not support mark/reset and `reset()` throws, as `InputStream` allows
when `markSupported()` is false.
### Changes
```java
@Override
public boolean markSupported() {
return false;
}
@Override
public synchronized void reset() throws IOException {
throw new IOException("mark/reset not supported");
}
```
### Test
`ChunkedBytesStreamTest.testMarkAndResetNotSupported` asserts
`markSupported()` is `false` and that `reset()` throws.
Without the change: `ChunkedBytesStreamTest > testMarkAndResetNotSupported()
FAILED`, 53 tests completed, 1 failed.
With it: `BUILD SUCCESSFUL`; `compress.*` (3467 tests) and
spotless/checkstyle are clean.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]