Throw IllegalStateException from Util.gzip() instead of AssertionError

The documentation on ByteArrayOutputStream and GZIPOutputStream isn't
completely clear that an IOException will *never* happen, so
AssertionError seems a bit strong - but it seems very unlikely, so we
just use IllegalStateException instead.

#minor-release

PiperOrigin-RevId: 387169297
This commit is contained in:
ibaker 2021-07-27 20:27:03 +01:00 committed by Andrew Lewis
parent 1aa76b5fdc
commit 41fe5aa1e3

View File

@ -2116,7 +2116,9 @@ public final class Util {
try (GZIPOutputStream os = new GZIPOutputStream(output)) {
os.write(input);
} catch (IOException e) {
throw new AssertionError(e);
// A ByteArrayOutputStream wrapped in a GZipOutputStream should never throw IOException since
// no I/O is happening.
throw new IllegalStateException(e);
}
return output.toByteArray();
}