Mismatch between spec and implementation of DataInputStream.readFully(byte[], int, int)

Brian Burkhalter brian.burkhalter at oracle.com
Thu May 14 15:25:48 UTC 2020


Hi Johannes,

> On May 14, 2020, at 7:24 AM, Johannes Kuhn <info at j-kuhn.de> wrote:
> 
> Found a small mismatch between the specification of DataInputStream.readFully(byte[] b, int off, int len) and its implementation.
> 
> In particular, it doesn't throw an IndexOutOfBoundsException if offset is negative and len is 0.

It looks like you are correct. Objects.checkFromIndexSize() should ideally be used here [1].

> Reproducer below.
> 
> I suggest changing the specification of this method to allow that behavior.

The usual practice for longstanding API discrepancies is to change the spec to match the behavior.

> This change should also affect DataInput, where care has to be taken that both behaviors are legal.

I’ll file an issue.

Thanks,

Brian

[1] https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/util/Objects.html#checkFromIndexSize(int,int,int)


More information about the core-libs-dev mailing list