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

DatagramPacket.setData has strange semantics

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.2.0
    • core-libs
    • None
    • beta
    • sparc
    • solaris_2.6

      DatagramPacket.setData has the following definition:
       
         public synchronized void setData(byte[] buf) {
      if (buf == null) {
      throw new NullPointerException("null packet buffer");
      }
      this.buf = buf;

      if (length > buf.length) {
      setLength(buf.length);
      }
          }

      This is strange because it leaves offset unchanged, and only changes
      length if buf.length is less than length. This is incosistent with
      setData(byte[] buf, int offset, int length)
      which sets both offset and length. The intuitive behavior for
      setData(buf) would be that it be equivalent to
      setData(buf, 0, buf.length), but it is not.

      A minor doc error is that
          public synchronized void setData(byte[] buf, int offset, int length) {
      says it is @since JDK1.1. This is not true, because this overload was
      introduced in JDK1.2.

            alanb Alan Bateman
            rleesunw Rosanna Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: