Index: C:/harmony/trunk_0427/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java =================================================================== --- C:/harmony/trunk_0427/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java (revision 423729) +++ C:/harmony/trunk_0427/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java (working copy) @@ -380,7 +380,7 @@ */ public long read(ByteBuffer[] targets, int offset, int length) throws IOException { - if (length < 0 || offset < 0 || length + offset > targets.length) { + if (length < 0 || offset < 0 || (long)length + (long)offset > targets.length) { throw new IndexOutOfBoundsException(); } // status must be open and connected @@ -470,7 +470,7 @@ */ public long write(ByteBuffer[] sources, int offset, int length) throws IOException { - if (length < 0 || offset < 0 || length + offset > sources.length) { + if (length < 0 || offset < 0 || (long)length + (long)offset > sources.length) { throw new IndexOutOfBoundsException(); } // status must be open and connected Index: C:/harmony/trunk_0427/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java =================================================================== --- C:/harmony/trunk_0427/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java (revision 423729) +++ C:/harmony/trunk_0427/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java (working copy) @@ -1863,6 +1863,19 @@ assertEquals(0, this.channel1.read(readBuf, 0, 1)); assertEquals(0, this.channel1.read(readBuf, 0, 2)); datagramSocket1.close(); + //regression test for HARMONY-932 + try { + DatagramChannel.open().read(new ByteBuffer[] {}, 2, Integer.MAX_VALUE); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + // correct + } + try { + DatagramChannel.open().write(new ByteBuffer[] {}, 2, Integer.MAX_VALUE); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + // correct + } } public void testReadByteBufferArrayIntInt_BufNull() throws IOException {