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

DatagramPacket exception conditions are not clear

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 15
    • 6
    • core-libs
    • None
    • b10

    Description

      DatagramPacket class does not have proper documentation for exception conditions.
      This makes it quite diffucult to develop compatibility tests for such class.


      1. public DatagramPacket(byte[] buf, int length)

      No exception conditions are documented.
      NPE should be thrown for null buf. IAE should be thrown when length is <=0 or > buf.length

      2. public DatagramPacket(byte[] buf,
                    int length,
                    InetAddress address,
                    int port)

      No exception conditions are documented.
      NPE should be thrown for null buf. IAE should be thrown when length is <=0 or > buf.length
      Yet it it is not clear what happens when address is null or port is <=0

      3. public DatagramPacket(byte[] buf,
                    int offset,
                    int length)

      No exception conditions are documented.
      NPE should be thrown for null buf. IAE should be thrown when offset is <0, or length is <=0 or (offset+length) > buf.length

      4. public DatagramPacket(byte[] buf,
                    int offset,
                    int length,
                    InetAddress address,
                    int port)
      No exception conditions are documented.
      NPE should be thrown for null buf. IAE should be thrown when offset is <0, or length is <=0 or (offset+length) > buf.length
      Yet it it is not clear what happens when address is null or port is <=0

      5.
      public DatagramPacket(byte[] buf,
                    int offset,
                    int length,
                    SocketAddress address)
                     throws SocketException
      SocketException condition is not explained at all
      NPE and IAE are not documented.
      NPE should be thrown for null buf. IAE should be thrown when offset is <0, or length is <=0 or (offset+length) > buf.length
      Yet it it is not clear what happens when address is null

      6. public DatagramPacket(byte[] buf,
                    int length,
                    SocketAddress address)
                     throws SocketException

      SocketException condition is not explained at all
      NPE and IAE are not documented.
      NPE should be thrown for null buf. IAE should be thrown when length is <=0 or > buf.length
      Yet it it is not clear what happens when address is null

      7. public void setAddress(InetAddress iaddr)
      It is not clear what happens when address is null

      8. public void setData(byte[] buf,
                 int offset,
                 int length)

      IAE is not documented
      It should be thrown when offset is <0, or length is <=0 or (offset+length) > buf.length

      9. public void setLength(int length)
      Throws:
          IllegalArgumentException - if the length is negative of if the length is greater than the packet's data buffer length.

      Exception condition does not take offset into account

      10. public void setPort(int iport)

      Meaning of negattove port is not clear

      Attachments

        Issue Links

          Activity

            People

              pconcannon Patrick Concannon (Inactive)
              sreznick Sergey Reznick (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: