On Fri, 4 Dec 2020 14:32:37 GMT, Yasumasa Suenaga <ysuen...@openjdk.org> wrote:

>> src/java.net.http/share/classes/jdk/internal/net/http/RequestPublishers.java 
>> line 422:
>> 
>>> 420:             } catch (IOException ex) {
>>> 421:                 need2Read = false;
>>> 422:                 haveNext = false;
>> 
>> This shouldn't be required - `need2Read`/`haveNext` will be set by 
>> `hasNext()`; I'd prefer if we kept the logic there.
>
> We can close the stream in `hasNext()`, but we need to move `close()` from 
> `read()`.
> `need2Read` and `haveNext` will be set to `false` if `read()` returns -1. 
> However `read()` returns -1 when IOE or EOF happen. Is it ok? I concern to 
> change location of `close()` - it means the change of side-effect.

You misunderstand. `read()` should call `close();` when `read` returns `-1`, 
`hasNext()` will take care of updating `need2Read` and `haveNext`;

But now I'm no longer convinced that returning -1 when an exception occurs in 
the wrapped `InputStreeam::read` call is the right thing to do.

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

PR: https://git.openjdk.java.net/jdk/pull/1614

Reply via email to