RFR JDK-8029804: (spec) BufferedWriter.write(String, int, int) IndexOutOfBoundsException

Roger Riggs Roger.Riggs at Oracle.com
Tue Apr 28 21:22:20 UTC 2015


Hi Pavel,

That looks ok.

It would be a bit more comfortable to read and compare with the parent 
contract
if it could use the len < 0 phrase.
But as written it clearly matches the implementation and is logically 
equivalent.

Roger


On 4/27/2015 12:48 PM, Pavel Rappo wrote:
> Hi everyone,
>
> Could you please review my change for JDK-8029804
>
> http://cr.openjdk.java.net/~prappo/8029804/webrev.00/
>
> -------------------------------------------------------------------------------
> There is an issue where java.io.BufferedWriter.write(String s, int off, int len)
> doesn't check required preconditions for `off` and `len` and goes straight to
> the algorithm procedures. As a result an acceptable region for (off, len) is
> wider than the one declared by parent. For example, following calls should throw
> IndexOutOfBoundsException, but they don't:
>
>      bw.write("abc", 10,   0)
>      bw.write("abc",  5,  -1)
>      bw.write("abc", -7,   0)
>      bw.write("abc", -2,  -3)
>      bw.write("abc",  3, Integer.MAX_VALUE)
>
> The problem though is not in the bug itself (it's been there for a long time),
> but rather than the amendment to the javadoc which supposed to describe this
> divergence is not comprehensive:
>
>       * <p> If the value of the <tt>len</tt> parameter is negative then no
>       * characters are written.  This is contrary to the specification of this
>       * method in the {@linkplain java.io.Writer#write(java.lang.String,int,int)
>       * superclass}, which requires that an {@link IndexOutOfBoundsException} be
>       * thrown.
>
> Suggested solution is to update the javadoc and provide a test that gives a
> certain amount of confidence that the javadoc captures the actual contract.
>
>   -Pavel
>




More information about the core-libs-dev mailing list