JDK-7113208 : Incorrect javadoc on java.net.DatagramPacket.setLength()
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-11-18
  • Updated: 2022-10-12
  • Resolved: 2022-09-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 20
20 b14Fixed
Related Reports
Relates :  
Relates :  
Description
Java Documents Error in java.net.DatagramPacket

public void setLength(int length)

Set the length for this packet. The length of the packet is the number of bytes from the packet's data buffer that will be sent, or the number of bytes of the packet's data buffer that will be used for receiving data. The length must be lesser or equal to the offset plus the length of the packet's buffer.

source code for java.net.DatagramPacket

public synchronized void setLength(int length) {
        if ((length + offset) > buf.length || length < 0 ||
            (length + offset) < 0) {
            throw new IllegalArgumentException("illegal length");
        }
        this.length = length;
        this.bufLength = this.length;
    }


"The length must be lesser or equal to the offset plus the length of the packet's buffer." is misleading. The relation should be described as "The length plus the offset should be lesser or equal to the packet's fuffer."

Comments
Changeset: a366e82a Author: Jaikiran Pai <jpai@openjdk.org> Date: 2022-09-03 05:48:20 +0000 URL: https://git.openjdk.org/jdk/commit/a366e82aa1177f001d49f297c6e1d29ee283ca59
03-09-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/10037 Date: 2022-08-26 07:51:16 +0000
26-08-2022

EVALUATION javadoc correction.
18-11-2011