[OpenJDK 2D-Dev] 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
Brian Burkhalter
brian.burkhalter at oracle.com
Wed Jul 24 20:54:44 UTC 2019
> On Jul 23, 2019, at 11:58 PM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
>
> On 23/07/2019 17:41, Brian Burkhalter wrote:
>> :
>>
>> Here is an update which accounts for the foregoing comments.
>>
>> http://cr.openjdk.java.net/~bpb/8187898/webrev-alt.02/ <http://cr.openjdk.java.net/~bpb/8187898/webrev-alt.02/>
>>
> I looked at this version, and webrev-alt.03, but I think PS.write(byte[]) will need further word smiting to properly explain the confusion on using PrintStream vs. sub-classes of PrintStream that override this method (the former does not throw IOE, the latter may). So I think the @apiNote will be expanded further and the recommendation to use writeBytes(byte[]) or write(byte[],0,len) instead should be dialed up. The @implSpec also needs to be expanded as it doesn't make it clear that the default implementation (by way of invoking super.write(byte[],int,int)) does not throw IOE. I'm also wondering if PS.write(byte[]) should be deprecated. Hard to know how much time to spend on this issue as it has existed since JDK 1.0.
Before addressing any of the above I wanted to note that in the fix for a very similar issue [1], where we added writeBytes(byte[]) to ByteArrayOutputStream, we did not do anything to its write(byte[]) method, i.e., it still does not override write(byte[]). I wonder whether doing the same here might simplify things.
If we are going to keep the write(byte[]) override, then perhaps it would be better to implement it to call out.write(buf,0,buf.length) directly.
Thanks,
Brian
[1] https://bugs.openjdk.java.net/browse/JDK-8180410
More information about the core-libs-dev
mailing list