utkarsh-009 opened a new issue, #16554: URL: https://github.com/apache/dubbo/issues/16554
### Version Current `3.3` branch, reproduced from `1afcdf7` (3.3.7-SNAPSHOT). ### Reproduction ```java InputStream stream = new UnsafeByteArrayInputStream(new byte[0]); int result = stream.read(new byte[1], 0, 0); // result is -1 ``` The same result occurs after consuming a non-empty stream or a bounded slice. The inherited `read(new byte[0])` overload also returns `-1` at EOF. ### Expected behavior A valid zero-length read should return `0` without modifying the destination or advancing the stream, including at EOF. Null and invalid offset/length arguments should still be validated first. Positive-length reads at EOF should continue returning `-1`. The base [InputStream.read(byte[], int, int) contract](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/InputStream.html#read(byte%5B%5D,int,int)) specifies this zero-length behavior. ### Compatibility qualification The JDK explicitly documents that [ByteArrayInputStream](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/ByteArrayInputStream.html#read(byte%5B%5D,int,int)) returns `-1` for a zero-length read at EOF, unlike InputStream. Dubbo's class extends InputStream directly and does not document that exception. This report proposes following the base contract; it does not claim a difference from ByteArrayInputStream or demonstrate a production outage. This is a narrow behavioral change for callers relying on the existing EOF result. ### Cause and proposed correction The EOF check currently runs before the zero-length check. Handle `len == 0` after argument validation and before EOF detection. Regression cases cover empty streams, exhausted streams and slices, valid destination offsets including the end of the buffer, the inherited read overload, unchanged buffer/position, and invalid arguments. Investigation and patch preparation were AI-assisted. This report is separate from metadata-export issue #14646 and the already-open skip-overflow fix #16523. -- 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]
