RFR 8180410: ByteArrayOutputStream should not throw IOExceptions

Stuart Marks stuart.marks at oracle.com
Wed Mar 21 19:34:13 UTC 2018



On 3/21/18 11:27 AM, Brian Burkhalter wrote:
> --- a/src/java.base/share/classes/java/io/ByteArrayOutputStream.java
> +++ b/src/java.base/share/classes/java/io/ByteArrayOutputStream.java
> @@ -158,15 +158,16 @@
>           count += len;
>       }
>   
>       /**
>        * Writes the complete contents of the specified byte array
>        * to this {@code ByteArrayOutputStream}.
>        *
> -     * <p> This method is equivalent to {@link #write(byte[],int,int)
> +     * @implSpec
> +     * This method is equivalent to {@link #write(byte[],int,int)
>        * write(b ,0, b.length)}.
>        *
>        * @param   b     the data.
>        * @throws  NullPointerException if {@code b} is {@code null}.
>        * @since   11
>        */
>       public void writeBytes(byte b[]) {

Sorry, this is an @apiNote, not an @implSpec.

Having this as an @implSpec sounds as if the implementation of this method in 
BAOS is *required* to call write(b, 0, b.length). It happens to do that in the 
current webrev, but this is not a requirement on the implementation. (At least 
that doesn't appear to be the intent.)

Instead, this statement explains and clarifies, but otherwise doesn't add any 
testable assertions or change any semantics of the contract specified in the 
first sentence of the doc. Thus, it's a note on the API.

Thanks,

s'marks

> 
> Thanks,
> 
> Brina
> 
> On Mar 21, 2018, at 10:00 AM, Brian Burkhalter <brian.burkhalter at oracle.com> wrote:
> 
>> I’ll change before pushing.
>>
>> Thanks,
>>
>> Brian
>>
>> On Mar 21, 2018, at 9:58 AM, Roger Riggs <Roger.Riggs at Oracle.com> wrote:
>>
>>> An @impSpec for that is fine with me.
> 


More information about the core-libs-dev mailing list