Skip to content

Commit 072e999

Browse files
committed
core: Hard-code mark/reset as unsupported in LazyDecompressingInputStream
Decompression streams do not support mark/reset. Hard-code markSupported() to return false, mark() as a no-op, and reset() to throw IOException so they do not trigger lazy decompressor initialization. TAG=agy CONV=5c954ab1-4fdf-4f8f-94e0-4b76f2bb9d07
1 parent f237d2f commit 072e999

2 files changed

Lines changed: 6 additions & 14 deletions

File tree

‎core/src/main/java/io/grpc/internal/MessageDeframer.java‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -511,28 +511,17 @@ public synchronized void close() throws IOException {
511511

512512
@Override
513513
public synchronized void mark(int readlimit) {
514-
try {
515-
ensureInitialized();
516-
super.mark(readlimit);
517-
} catch (IOException e) {
518-
throw new RuntimeException(e);
519-
}
514+
// Mark is not supported
520515
}
521516

522517
@Override
523518
public synchronized void reset() throws IOException {
524-
ensureInitialized();
525-
super.reset();
519+
throw new IOException("Mark not supported");
526520
}
527521

528522
@Override
529523
public boolean markSupported() {
530-
try {
531-
ensureInitialized();
532-
return super.markSupported();
533-
} catch (IOException e) {
534-
throw new RuntimeException(e);
535-
}
524+
return false;
536525
}
537526
}
538527

‎core/src/test/java/io/grpc/internal/MessageDeframerTest.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,9 @@ public InputStream decompress(InputStream is) throws IOException {
593593
LazyDecompressingInputStream stream = new LazyDecompressingInputStream(
594594
in, 100, statsTraceCtx, countingDecompressor);
595595

596+
assertFalse(stream.markSupported());
597+
stream.mark(10);
598+
assertThrows(IOException.class, () -> stream.reset());
596599
assertFalse(decompressCalled.get());
597600
byte[] buf = new byte[5];
598601
int read = stream.read(buf);

0 commit comments

Comments
 (0)