On Thu, 19 Mar 2026 18:15:03 GMT, Alan Bateman <[email protected]> wrote:

> Can you check the other usages of ZipCode.getBytes to see if this merits an 
> overload of getBytes that throws ZipException rather than IllegalArgument.

`ZipFileOutputStream` is actualy the sole client of `ZipCoder::getBytes`. I'm 
not really sure why it wraps the CCE in IAE instead of just declaring that it 
throws CCE. Perhaps someone wanted to avoid dependency on `java.nio.charset`, 
perhaps historically overrides threw different exceptions so there was a need 
to consolidate on a single exception type. This is currently the case for 
`checkedHash`.
 
> These malformed-input and unmappable-character cases will cause 
> CharacterCodingException to be thrown so it must be caught to throw 
> IllegalArgument, then caught to throw ZipException, and we should be able to 
> do better.

I'm a bit reluctant to introduce an overload throwing ZipException since Lance 
have been discussing a future where ZipCoder is used from ZipFileSystem. A 
ZipException throws would not be useful there.

I could update the PR such that ZipCoder.getBytes throws 
CharacterCodingException directly instead of rethrowing IAE. Would you like me 
to go down that road?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/30319#discussion_r2962010172

Reply via email to