RFR: 7113208: Incorrect javadoc on java.net.DatagramPacket.setLength()

Daniel Fuchs dfuchs at openjdk.org
Fri Aug 26 08:59:05 UTC 2022


On Fri, 26 Aug 2022 07:51:16 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:

> Can I please get a review of this javadoc only change for `DatagramPacket#setLength()` method? This addresses https://bugs.openjdk.org/browse/JDK-7113208.
> 
> I haven't create a CSR because the javadoc was already stating the correct behaviour in the `@throws` documentation as follows:
> 
>> @throws  IllegalArgumentException    if the length is negative,
>      *          or if the length plus the offset is greater than the
>      *          length of the packet's data buffer.
> 
> This commit merely fixes the main part of the javadoc.

src/java.base/share/classes/java/net/DatagramPacket.java line 399:

> 397:      * will be used for receiving data. The {@code length} plus the
> 398:      * {@link #getOffset() offset} must be lesser or equal to the
> 399:      * length of the packet's data buffer.

The new text looks good to me. While you're at it I would suggest to rewrite the code that checks the length with something like:


        Preconditions.checkFromIndexSize(offset, length, buf.length,
                Preconditions.outOfBoundsExceptionFormatter(IllegalArgumentException::new));


Then figure out if we have a unit test that already checks this, and if not, write one!

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

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


More information about the net-dev mailing list