Add argument checks
@@ -28,6 +28,23 @@ public int getSendLimit()
public int receive(byte[] buf, int off, int len, int waitMillis)
throws IOException
{
+ if (null == buf)
+ {
+ throw new NullPointerException("'buf' cannot be null");
+ }
+ if (off < 0 || off >= buf.length)
+ {
+ throw new IllegalArgumentException("'off' is an invalid offset: " + off);
+ }
+ if (len < 0 || len > buf.length - off)
+ {
+ throw new IllegalArgumentException("'len' is an invalid length: " + len);
+ }
+ if (waitMillis < 0)
+ {
+ throw new IllegalArgumentException("'waitMillis' cannot be negative");
+ }
+
try
{
return recordLayer.receive(buf, off, len, waitMillis);
@@ -56,6 +73,19 @@ public int receive(byte[] buf, int off, int len, int waitMillis)
public void send(byte[] buf, int off, int len)
throws IOException
{
+ if (null == buf)
+ {
+ throw new NullPointerException("'buf' cannot be null");
+ }
+ if (off < 0 || off >= buf.length)
+ {
+ throw new IllegalArgumentException("'off' is an invalid offset: " + off);
+ }
+ if (len < 0 || len > buf.length - off)
+ {
+ throw new IllegalArgumentException("'len' is an invalid length: " + len);
+ }
+
try
{
recordLayer.send(buf, off, len);
