8194649: Minor cleanup of parameter checking in ByteArrayOutputStream and ObjectInputStream
Reviewed-by: rriggs
This commit is contained in:
parent
1924909d78
commit
7be1368ad8
@ -27,6 +27,7 @@ package java.io;
|
|||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class implements an output stream in which the data is
|
* This class implements an output stream in which the data is
|
||||||
@ -147,10 +148,7 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||||||
* @param len the number of bytes to write.
|
* @param len the number of bytes to write.
|
||||||
*/
|
*/
|
||||||
public synchronized void write(byte b[], int off, int len) {
|
public synchronized void write(byte b[], int off, int len) {
|
||||||
if ((off < 0) || (off > b.length) || (len < 0) ||
|
Objects.checkFromIndexSize(off, len, b.length);
|
||||||
((off + len) - b.length > 0)) {
|
|
||||||
throw new IndexOutOfBoundsException();
|
|
||||||
}
|
|
||||||
ensureCapacity(count + len);
|
ensureCapacity(count + len);
|
||||||
System.arraycopy(b, off, buf, count, len);
|
System.arraycopy(b, off, buf, count, len);
|
||||||
count += len;
|
count += len;
|
||||||
|
@ -1296,7 +1296,6 @@ public class ObjectInputStream
|
|||||||
* @throws InvalidClassException if the filter rejects creation
|
* @throws InvalidClassException if the filter rejects creation
|
||||||
*/
|
*/
|
||||||
private void checkArray(Class<?> arrayType, int arrayLength) throws InvalidClassException {
|
private void checkArray(Class<?> arrayType, int arrayLength) throws InvalidClassException {
|
||||||
Objects.requireNonNull(arrayType);
|
|
||||||
if (! arrayType.isArray()) {
|
if (! arrayType.isArray()) {
|
||||||
throw new IllegalArgumentException("not an array type");
|
throw new IllegalArgumentException("not an array type");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user