Bug 4254082: java.io.BufferedInputStream.skip has unexpected results was closed Will Not Fix back in 2002.
Offhand, I can't think of any reason not to fix this as Bill suggests, but I'm pretty sure that there is some history with this bug, and I don't know what it is. Perhaps madbot remembers? Of course, the proposed change is an incompatible change, but then every bug fix is an incompatible change. Hmmmm...... wait.... let's search bug database... Some people were complaining about the opposite problem, namely that the Buffered stream tries to read too far on the underlying stream. 6192696: BufferedInputStream.read(byte[], int, int) can block if the entire buffer can't be filled http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6192696 4850305: BufferedReader.skip(long) blocks when it could return some data http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4850305 Chris, could you comment? Martin Bill Pugh wrote: > I'd like to submit a patch to fix BufferedInputStream.skip. > > This will fix the bad behavior described in > http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4254082 > although it doesn't fix the spec problem for InputStream.skip. > > As described in our Java Puzzlers talk at JavaOne, > BufferedInputStream.skip has a particularly unexpected behavior: if > skipping a sequence of bytes requires both skipping some buffered bytes > and some bytes in the underlying input stream, it will only skip the > buffered bytes, returning a value that indicates that the method call > only skipped those bytes. > > Unfortunately, that return value is usually ignored, including most of > the times skip is invoked in Sun's code base. > > I propose the following: > > * Rename the existing skip method to be a private method named skip1. > * Define a new public synchronized skip method that uses a loop to > invoke skip1 until either all the requested bytes are skipped, or > skip1 returns 0, and returns the total of all the calls to skip1. > > I could factor out some of the simple cases into the new skip method, > but I'm not sure that would buy any performance improvements except for > microbenchmarks, and it would avoid duplicating any logic. > > Sound good? Let me know and if this sounds acceptable I'll submit the > patch. > > Bill >
