[#3376] Use IllegalArgumentException as replacement for NPE as stated in javadocs

Motivation:

SSLEngine specifies that IllegalArgumentException must be thrown if a null argument is given when using wrap(...) or unwrap(...).

Modifications:

Replace NullPointerException with IllegalArgumentException to match the javadocs.

Result:

Match the javadocs.
This commit is contained in:
Norman Maurer 2015-01-25 20:44:47 +01:00
parent 1808374a63
commit e0f2e1e2a1

View File

@ -367,10 +367,10 @@ public final class OpenSslEngine extends SSLEngine {
// Throw required runtime exceptions
if (srcs == null) {
throw new NullPointerException("srcs");
throw new IllegalArgumentException("srcs is null");
}
if (dst == null) {
throw new NullPointerException("dst");
throw new IllegalArgumentException("dst is null");
}
if (offset >= srcs.length || offset + length > srcs.length) {
@ -430,6 +430,9 @@ public final class OpenSslEngine extends SSLEngine {
int endOffset = offset + length;
for (int i = offset; i < endOffset; ++ i) {
final ByteBuffer src = srcs[i];
if (src == null) {
throw new IllegalArgumentException("srcs[" + i + "] is null");
}
while (src.hasRemaining()) {
// Write plaintext application data to the SSL engine
@ -484,7 +487,7 @@ public final class OpenSslEngine extends SSLEngine {
" (expected: offset <= offset + length <= srcs.length (" + srcs.length + "))");
}
if (dsts == null) {
throw new NullPointerException("dsts");
throw new IllegalArgumentException("dsts is null");
}
if (dstsOffset >= dsts.length || dstsOffset + dstsLength > dsts.length) {
throw new IndexOutOfBoundsException(
@ -496,7 +499,7 @@ public final class OpenSslEngine extends SSLEngine {
for (int i = dstsOffset; i < endOffset; i ++) {
ByteBuffer dst = dsts[i];
if (dst == null) {
throw new IllegalArgumentException();
throw new IllegalArgumentException("dsts[" + i + "] is null");
}
if (dst.isReadOnly()) {
throw new ReadOnlyBufferException();
@ -521,7 +524,7 @@ public final class OpenSslEngine extends SSLEngine {
for (int i = srcsOffset; i < srcsEndOffset; i++) {
ByteBuffer src = srcs[i];
if (src == null) {
throw new NullPointerException("srcs[" + i + ']');
throw new IllegalArgumentException("srcs[" + i + "] is null");
}
len += src.remaining();
}