Summary
Add an inherited throws IndexOutOfBoundsException
to some write(byte[],int,int)
and read(byte[],int,int)
in various classes in the java.io
package.
Problem
The IndexOutOfBounds
exception is thrown by some methods but is not inherited in the javadoc as it is a RuntimeException
.
Solution
Explicitly force inheritance of IndexOutOfBoundsException
by using @inheritDoc
.
Specification
--- a/src/java.base/share/classes/java/io/BufferedInputStream.java
+++ b/src/java.base/share/classes/java/io/BufferedInputStream.java
@@ -355,6 +355,7 @@ private int read1(byte[] b, int off, int len) throws IOException {
* @throws IOException if this input stream has been closed by
* invoking its {@link #close()} method,
* or an I/O error occurs.
+ * @throws IndexOutOfBoundsException {@inheritDoc}
*/
public int read(byte[] b, int off, int len) throws IOException {
if (lock != null) {
--- a/src/java.base/share/classes/java/io/BufferedOutputStream.java
+++ b/src/java.base/share/classes/java/io/BufferedOutputStream.java
@@ -190,6 +190,7 @@ private void implWrite(int b) throws IOException {
* @param off the start offset in the data.
* @param len the number of bytes to write.
* @throws IOException if an I/O error occurs.
+ * @throws IndexOutOfBoundsException {@inheritDoc}
*/
@Override
public void write(byte[] b, int off, int len) throws IOException {
--- a/src/java.base/share/classes/java/io/DataOutputStream.java
+++ b/src/java.base/share/classes/java/io/DataOutputStream.java
@@ -104,6 +104,7 @@ public synchronized void write(int b) throws IOException {
* @param off the start offset in the data.
* @param len the number of bytes to write.
* @throws IOException if an I/O error occurs.
+ * @throws IndexOutOfBoundsException {@inheritDoc}
* @see java.io.FilterOutputStream#out
*/
public synchronized void write(byte[] b, int off, int len)
--- a/src/java.base/share/classes/java/io/FileOutputStream.java
+++ b/src/java.base/share/classes/java/io/FileOutputStream.java
@@ -363,6 +363,7 @@ public void write(byte[] b) throws IOException {
- @param off
{@inheritDoc}
* @param len {@inheritDoc}
- @throws IOException if an I/O error occurs.
+ * @throws IndexOutOfBoundsException
{@inheritDoc}
*/
@Override
public void write(byte[]
b, int off, int len) throws IOException {
--- a/src/java.base/share/classes/java/io/FilterOutputStream.java
+++ b/src/java.base/share/classes/java/io/FilterOutputStream.java
@@ -126,6 +126,7 @@ public void write(byte[] b) throws IOException {
* @param off {@inheritDoc}
* @param len {@inheritDoc}
* @throws IOException if an I/O error occurs.
+ * @throws IndexOutOfBoundsException {@inheritDoc}
* @see java.io.FilterOutputStream#write(int)
*/
@Override
--- a/src/java.base/share/classes/java/io/ObjectInput.java
+++ b/src/java.base/share/classes/java/io/ObjectInput.java
@@ -79,6 +79,9 @@ public Object readObject()
* {@code -1} if there is no more data because the end of
* the stream has been reached.
* @throws IOException If an I/O error has occurred.
+ * @throws IndexOutOfBoundsException If {@code off} is negative,
+ * {@code len} is negative, or {@code len} is greater than
+ * {@code b.length - off}
*/
public int read(byte[] b, int off, int len) throws IOException;
--- a/src/java.base/share/classes/java/io/ObjectOutput.java
+++ b/src/java.base/share/classes/java/io/ObjectOutput.java
@@ -69,6 +69,7 @@ public void writeObject(Object obj)
* @param off the start offset in the data
* @param len the number of bytes that are written
* @throws IOException If an I/O error has occurred.
+ * @throws IndexOutOfBoundsException {@inheritDoc}
*/
public void write(byte[] b, int off, int len) throws IOException;
--- a/src/java.base/share/classes/java/io/ObjectOutputStream.java
+++ b/src/java.base/share/classes/java/io/ObjectOutputStream.java
@@ -713,6 +713,7 @@ public void write(byte[] buf) throws IOException {
- @param off the start offset in the data
- @param len the number of bytes that are written
- @throws IOException
{@inheritDoc}
+ * @throws IndexOutOfBoundsException {@inheritDoc}
*/
@Override
public void write(byte[]
buf, int off, int len) throws IOException {
--- a/src/java.base/share/classes/java/io/OutputStream.java
+++ b/src/java.base/share/classes/java/io/OutputStream.java
@@ -156,6 +156,9 @@ public void write(byte[] b) throws IOException {
* @throws IOException if an I/O error occurs. In particular,
* an {@code IOException} is thrown if the output
* stream is closed.
+ * @throws IndexOutOfBoundsException If {@code off} is negative,
+ * {@code len} is negative, or {@code len} is greater than
+ * {@code b.length - off}
*/
public void write(byte[] b, int off, int len) throws IOException {
Objects.checkFromIndexSize(off, len, b.length);
--- a/src/java.base/share/classes/java/io/PipedOutputStream.java
+++ b/src/java.base/share/classes/java/io/PipedOutputStream.java
@@ -135,6 +135,7 @@ public void write(int b) throws IOException {
* @throws IOException if the pipe is <a href=#BROKEN> broken</a>,
* {@link #connect(java.io.PipedInputStream) unconnected},
* closed, or if an I/O error occurs.
+ * @throws IndexOutOfBoundsException {@inheritDoc}
*/
@Override
public void write(byte[] b, int off, int len) throws IOException {
--- a/src/java.base/share/classes/java/io/PrintStream.java
+++ b/src/java.base/share/classes/java/io/PrintStream.java
@@ -612,6 +612,7 @@ private void implWrite(int b) throws IOException {
* @param buf A byte array
* @param off Offset from which to start taking bytes
* @param len Number of bytes to write
+ * @throws IndexOutOfBoundsException {@inheritDoc}
*/
@Override
public void write(byte[] buf, int off, int len) {
- csr of
-
JDK-8156593 DataOutput.write(byte[],int,int) and its implementations do not specify index out bounds
-
- Resolved
-