On Thu, 27 Jun 2024 05:12:18 GMT, Daniel Jeliński <djelin...@openjdk.org> wrote:

>> src/java.base/share/classes/sun/net/www/MeteredStream.java line 58:
>> 
>>> 56:         if (n == -1) {
>>> 57:             if (expected > count) {
>>> 58:                 throw new IOException("Premature EOF");
>> 
>> Hello Daniel, should we instead throw `java.io.EOFException` which is much 
>> more precise than a generic `IOException`? `EOFException` states:
>> 
>> 
>>  * Signals that an end of file or end of stream has been reached
>>  * unexpectedly during input.
>> 
>> which I think accurately depicts what's happening here.
>
> Hi Jaikiran, I used IOException because that's already used by the 
> ChunkedInputStream:
> 
> https://github.com/openjdk/jdk/blob/409a3fe601c61451e36554d57f29e661fe16058a/src/java.base/share/classes/sun/net/www/http/ChunkedInputStream.java#L257
> 
> No code in sun.net uses EOFException today. I suppose I could change that, 
> but it might require changes in more places.

EOFException is an IOException too, so I think it would be OK to change them to 
throw this specific exception.

For this current PR, i think it's OK to use the IOException since like you note 
it maintains consistency with the other places. We can think of changing these 
relevant places to use EOFException as a separate task.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/19909#discussion_r1656452536

Reply via email to