Skip to content

Commit

Permalink
8156593: DataOutput.write(byte[],int,int) and its implementations do …
Browse files Browse the repository at this point in the history
…not specify index out bounds

Reviewed-by: alanb, aturbanov
  • Loading branch information
Brian Burkhalter committed Oct 31, 2022
1 parent 8480f87 commit 4999f2c
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/java.base/share/classes/java/io/DataOutputStream.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/java.base/share/classes/java/io/FileOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/java.base/share/classes/java/io/ObjectInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/java.base/share/classes/java/io/ObjectOutput.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/java.base/share/classes/java/io/OutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/java.base/share/classes/java/io/PipedOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/java.base/share/classes/java/io/PrintStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

3 comments on commit 4999f2c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhaosongzs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please ignore this comment, just do some tests
/backport playground

@openjdk
Copy link

@openjdk openjdk bot commented on 4999f2c Jan 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhaosongzs The target repository playground is not a valid target for backports.
List of valid target repositories: openjdk/jdk, openjdk/jdk11u, openjdk/jdk11u-dev, openjdk/jdk12u, openjdk/jdk13u, openjdk/jdk13u-dev, openjdk/jdk14u, openjdk/jdk15u, openjdk/jdk15u-dev, openjdk/jdk16u, openjdk/jdk17u, openjdk/jdk17u-dev, openjdk/jdk19u, openjdk/jdk20, openjdk/jdk20u, openjdk/jdk7u, openjdk/jdk8u, openjdk/jdk8u-dev, openjdk/shenandoah-jdk8u, openjdk/shenandoah-jdk8u-dev.
Supplying the organization/group prefix is optional.

Please sign in to comment.