RFR: 8279283 - BufferedInputStream should override transferTo [v7]

Markus KARG duke at openjdk.org
Tue Sep 6 08:00:03 UTC 2022


On Mon, 5 Sep 2022 20:21:01 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> Markus KARG has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   HexPrinter::transferTo
>
> test/lib/jdk/test/lib/hexdump/HexPrinter.java line 1194:
> 
>> 1192:             byteOffset += size;
>> 1193:             return size;
>> 1194:         }
> 
> This is an indication that overriding `transferTo()` in `BufferedInputStream` has potential compatibility impacts on its subclasses. Therefore I would suggest adding a check in `BufferedInputStream::transferTo` to only override the behavior if not subclassed. Something like:
> 
> 
>      if (this.getClass() != BufferedInputStream.class) {
>          // a custom subclass may have expectations on which
>          // methods tansferTo() will call. Revert to super class
>          // behavior for compatibility.
>          return super.transferTo(out);
>      }
>      ... otherwise proceed with the new implementation ...
> 
> 
> Then you can revert the changes in this test.

I do not see that it makes much sense to add such a safety means before I am finished with the inspection of the subclasses. As you can see in this example, it was pretty easy to fix it, and there are only few such subclasses at all. So instead of preparing against possibly non-existing easyt-to-fix problems, I prefer fixing the actual problems. They can only occur inside of the JDK itself, as relying on any particular implementation inside of the JDK by non-JDK classes simply would be a complete programming fault and *must* get fixed.

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

PR: https://git.openjdk.org/jdk/pull/6935


More information about the core-libs-dev mailing list