On Tue, 6 Sep 2022 12:32:46 GMT, Markus KARG <d...@openjdk.org> wrote:
>> BIS dates from JDK 1.0 and it's not hard to find examples that extend it. >> The HexPrinter test reminds us that it has been possible for 25+ years to >> override the read methods and snoop on all bytes that are read. Adding an >> override of the transferTo method that bypasses the read methods might break >> these subclasses. So I think Daniel is right that we have to be cautious. >> >> So I think the feedback that you have now is that bypassing the buffer is >> problematic when using mark, when there are buffered bytes, or when BIS has >> been extended. It may be that the starting point is something very >> conservative like this: >> >> >> @Override >> public long transferTo(OutputStream out) throws IOException { >> if (getClass() == BufferedInputStream.class >> && ((count - pos) <= 0) && (markpos == -1)) { >> return getInIfOpen().transferTo(out); >> } else { >> return super.transferTo(out); >> } >> } >> >> >> There is also the issue of locking and async close to look into. > > Thank you for your decision about this issue, so instead of fixing the > existing bugs I will implement as you outlined. > > BTW, locking and rebasing is on the way. Rebased and fixed locking, using your proposed code now. @AlanBateman Async close leaves BIS in an invalid state. The JavaDocs say ` The behavior for the case where the inputand/or output stream is asynchronously closed, or the thread interrupted during the transfer, is highly input and output streamspecific, and therefore not specified.`. So there is seems to be no *essential* need to do something *particular* in that case (the caller cannot further use the BIS, just like after an IOE: `It is strongly recommended that both streams be promptly closed if an I/O error occurs.` -- which is what *I personally, as a user of BIS* would do after async close), but if you *want* that we reach a particular outcome, then just tell me what outcome you envision. ------------- PR: https://git.openjdk.org/jdk/pull/6935