JDK-7021373 : DatagramPacket exception conditions are not clear
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2011-02-22
  • Updated: 2020-02-13
  • Resolved: 2020-02-07
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 15
15 b10Fixed
Related Reports
CSR :  
Duplicate :  
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

Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/f41394559814 User: pconcannon Date: 2020-02-07 11:14:04 +0000
07-02-2020