changeset 48527:45a9a7a49379

8194649: Minor cleanup of parameter checking in ByteArrayOutputStream and ObjectInputStream Reviewed-by: rriggs
author bpb
date Fri, 05 Jan 2018 12:46:22 -0800
parents 20fe8cd3179d
children c10b8e775610
files src/java.base/share/classes/java/io/ByteArrayOutputStream.java src/java.base/share/classes/java/io/ObjectInputStream.java
diffstat 2 files changed, 2 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/io/ByteArrayOutputStream.java	Fri Jan 05 12:45:52 2018 -0800
+++ b/src/java.base/share/classes/java/io/ByteArrayOutputStream.java	Fri Jan 05 12:46:22 2018 -0800
@@ -27,6 +27,7 @@
 
 import java.nio.charset.Charset;
 import java.util.Arrays;
+import java.util.Objects;
 
 /**
  * This class implements an output stream in which the data is
@@ -147,10 +148,7 @@
      * @param   len   the number of bytes to write.
      */
     public synchronized void write(byte b[], int off, int len) {
-        if ((off < 0) || (off > b.length) || (len < 0) ||
-            ((off + len) - b.length > 0)) {
-            throw new IndexOutOfBoundsException();
-        }
+        Objects.checkFromIndexSize(off, len, b.length);
         ensureCapacity(count + len);
         System.arraycopy(b, off, buf, count, len);
         count += len;
--- a/src/java.base/share/classes/java/io/ObjectInputStream.java	Fri Jan 05 12:45:52 2018 -0800
+++ b/src/java.base/share/classes/java/io/ObjectInputStream.java	Fri Jan 05 12:46:22 2018 -0800
@@ -1296,7 +1296,6 @@
      * @throws InvalidClassException if the filter rejects creation
      */
     private void checkArray(Class<?> arrayType, int arrayLength) throws InvalidClassException {
-        Objects.requireNonNull(arrayType);
         if (! arrayType.isArray()) {
             throw new IllegalArgumentException("not an array type");
         }