I was running into an issue today where writeInt() from the DataOutput2 class threw an ArrayOutOfBoundsException.
It was trying to write to position 1073741824 in the Buffer Array. As far as I can tell, ensureAvail() calls grow() which tries to double the Arraysize with DataIO.nextPowTwo(n) which then results in a negative value because 1073741824*2 equals maxInt+1.
newsize = Math.max(DataIO.nextPowTwo(n),buf.length) then keeps the old size, leading to an OutOfBoundsException on the next write to the byte buffer.
I was running into an issue today where writeInt() from the DataOutput2 class threw an ArrayOutOfBoundsException. It was trying to write to position 1073741824 in the Buffer Array. As far as I can tell, ensureAvail() calls grow() which tries to double the Arraysize with DataIO.nextPowTwo(n) which then results in a negative value because 1073741824*2 equals maxInt+1. newsize = Math.max(DataIO.nextPowTwo(n),buf.length) then keeps the old size, leading to an OutOfBoundsException on the next write to the byte buffer.