Skip to content

6766844: ByteArrayInputStream#read with a byte array of length 0 not consistent with InputStream when at EOF #4591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

bplb
Copy link
Member

@bplb bplb commented Jun 25, 2021

Modify java.io.ByteArrayInputStream methods read(byte[]) and read(byte[],int,int) to return zero per the InputStream specification when the byte array actual or specified length is zero.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-6766844: ByteArrayInputStream#read with a byte array of length 0 not consistent with InputStream when at EOF

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4591/head:pull/4591
$ git checkout pull/4591

Update a local copy of the PR:
$ git checkout pull/4591
$ git pull https://git.openjdk.java.net/jdk pull/4591/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4591

View PR using the GUI difftool:
$ git pr show -t 4591

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4591.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 25, 2021

👋 Welcome back bpb! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 25, 2021
@openjdk
Copy link

openjdk bot commented Jun 25, 2021

@bplb The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Jun 25, 2021
@mlbridge
Copy link

mlbridge bot commented Jun 25, 2021

Webrevs

@JoeWang-Java
Copy link
Member

Looks good to me. Maybe add the bug id to the @bug tag of the test.

@openjdk
Copy link

openjdk bot commented Jun 25, 2021

@bplb This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

6766844: ByteArrayInputStream#read with a byte array of length 0 not consistent with InputStream when at EOF

Reviewed-by: joehw, naoto

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 131 new commits pushed to the master branch:

  • 5c08344: 8269678: Remove unimplemented and unused os::bind_to_processor()
  • 83bce94: 8268457: XML Transformer outputs Unicode supplementary character incorrectly to HTML
  • 1810b1c: 8269516: AArch64: Assembler cleanups
  • a96012a: 8261495: Shenandoah: reconsider update references memory ordering
  • 23d2996: 8269478: Shenandoah: gc/shenandoah/mxbeans tests should be more resilient
  • a6b253d: 8269416: [JVMCI] capture libjvmci crash data to a file
  • a0f32cb: 8268906: gc/g1/mixedgc/TestOldGenCollectionUsage.java assumes that GCs take 1ms minimum
  • ee0247f: 8263461: jdk/jfr/event/gc/detailed/TestEvacuationFailedEvent.java uses wrong mechanism to cause evacuation failure
  • 3ad20fc: 8269571: NMT should print total malloc bytes and invocation count
  • b969136: 8245877: assert(_value != __null) failed: resolving NULL _value in JvmtiExport::post_compiled_method_load
  • ... and 121 more: https://git.openjdk.java.net/jdk/compare/cd20c01942dd8559a31e51ef2a595c6eba44b8ad...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 25, 2021
@bplb
Copy link
Member Author

bplb commented Jun 25, 2021

Yeah I overlooked adding the bug ID to the test.

@AlanBateman
Copy link
Contributor

/csr

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Jun 25, 2021
@openjdk
Copy link

openjdk bot commented Jun 25, 2021

@AlanBateman has indicated that a compatibility and specification (CSR) request is needed for this pull request.
@bplb please create a CSR request for issue JDK-6766844. This pull request cannot be integrated until the CSR request is approved.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jun 25, 2021
@AlanBateman
Copy link
Contributor

I realize I submitted this issue a long time ago but I think we have to proceed with caution as it is changing long standing behavior. Reading with len==0 will arise with code that is reading in a loop and the "previous read" completely fills the array and reads all remaining bytes. It's possible that there is existing code that will break with this change. I've added the "csr" label for now. If this changes goes ahead then it will need a release note too.

@bplb
Copy link
Member Author

bplb commented Jun 25, 2021

I had the same misgivings after creating this PR and thought that a CSR would be in order.

@bplb
Copy link
Member Author

bplb commented Jun 25, 2021

CSR JDK-8269399 created.

@RogerRiggs
Copy link
Contributor

The spec for ByteArrayInputStream.read(byte[], off, len) is pretty specific about returning -1 if there is nothing to read.
The spec inherited from InputStream doesn't supercede javadoc of BAIS.
If the implementation is going to change then the spec will need to change too.
It seems safer to document the inconsistency and avoid the risk of infinite loops.

@bplb
Copy link
Member Author

bplb commented Jun 25, 2021

@RogerRiggs I agree.

@bplb bplb force-pushed the ByteArrayInputStream-read-6766844 branch from 3152cdc to df884a4 Compare June 25, 2021 20:41
@bplb bplb force-pushed the ByteArrayInputStream-read-6766844 branch from df884a4 to a53849a Compare June 25, 2021 20:42
Copy link
Member

@naotoj naotoj left a comment

Choose a reason for hiding this comment

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

Agree that clarifying the spec would be a much safer solution.

@bplb
Copy link
Member Author

bplb commented Jun 30, 2021

CSR revised to match.

@openjdk openjdk bot added ready Pull request is ready to be integrated and removed csr Pull request needs approved CSR before integration labels Jun 30, 2021
@bplb
Copy link
Member Author

bplb commented Jun 30, 2021

This PR has been superseded by the JDK 17 PR 189.

@bplb bplb closed this Jun 30, 2021
@bplb bplb deleted the ByteArrayInputStream-read-6766844 branch June 30, 2021 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org ready Pull request is ready to be integrated rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

5 participants