Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7113208

Incorrect javadoc on java.net.DatagramPacket.setLength()

XMLWordPrintable

    • b14
    • generic
    • generic

      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."

            jpai Jaikiran Pai
            amjiang Amanda Jiang (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: