utkarsh-009 opened a new pull request, #16555: URL: https://github.com/apache/dubbo/pull/16555
## What is the purpose of the change? Fixes #16554 `UnsafeByteArrayInputStream.read(byte[], off, 0)` currently returns `-1` when the stream is empty or exhausted because the EOF check precedes the zero-length check. The inherited `read(new byte[0])` overload is affected as well. Return `0` for a valid zero-length read before checking EOF, while retaining null/bounds validation first. Positive-length EOF reads still return `-1`. No bytes are copied and the position is unchanged. ### Compatibility The base [InputStream contract](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/InputStream.html#read(byte%5B%5D,int,int)) requires this result. The JDK explicitly documents [ByteArrayInputStream's different EOF behavior](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/ByteArrayInputStream.html#read(byte%5B%5D,int,int)); this PR deliberately follows InputStream rather than claiming parity with ByteArrayInputStream. Dubbo extends InputStream directly and does not document the exception. Callers depending on the old zero-length EOF result will observe a change. No production outage is claimed. ### Validation - Before the fix: the focused class ran 16 test invocations; all five new EOF parameter cases failed with expected `0`, actual `-1`. - After the fix: all 53 I/O-package test invocations passed, including all 16 stream tests, with zero failures, errors, or skips. - Coverage includes empty and exhausted streams/slices, end-of-buffer offsets, inherited empty-array reads, unchanged destination/position, ordinary positive-length EOF, and null/invalid-offset validation. - Maven lifecycle Spotless checks and `git diff --check` passed. ```text mvn -B -pl dubbo-common -am -Dtest=org.apache.dubbo.common.io.*Test -Dsurefire.failIfNoSpecifiedTests=false test ``` The project compiled with release 8. Full-repository tests and production-network testing were not run. ## Checklist - [x] Linked reproducible GitHub issue. - [x] Description explains the trigger, change, and compatibility qualification. - [x] Regression failures reproduced before the fix; focused package tests pass afterward. - [x] Local formatting and whitespace checks pass. - [ ] GitHub Actions: pending this PR; not claimed as passed. Investigation and patch preparation were AI-assisted; the reported local checks were actually executed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
