6516099: InputStream.skipFully(int k) to skip exactly k bytes

Brian Burkhalter brian.burkhalter at oracle.com
Fri Nov 2 16:29:05 UTC 2018


Hi Daniel,

> On Nov 2, 2018, at 3:40 AM, Daniel Fuchs <daniel.fuchs at oracle.com> wrote:
> 
> If skip(n) returns a negative number, e.g. -1, then you might
> end up skipping more than n bytes (unless skip returning
> -1 indicates that EOF was reached).

I suppose you mean line 571:

 571         if (n > 0 && (n -= skip(n)) > 0) {

I was assuming that if n > 0, then skip(n) will (usually) return a value in [0,n] although given the weird specification of FIS it might return something in [0,m] where m > n. Perhaps that assumption is wrong.

> Basically, I don't think you can make any guarantee of how
> many bytes will be skipped if a subclass has an implementation
> of skip that misbehave by returning -1 (or any other negative
> value).

If skip(n) for n > 0 returned a negative value then I would think that would be a subclass bug but then it would still be a problem ...

> Maybe there should be some @implSpec note to say that
> no guarantee is made if a subclass implementation of
> skip() returns non-positive (or non accurate) results?

Agreed.

Thanks,

Brian


More information about the core-libs-dev mailing list