Index: src/test/java/tests/api/java/io/ByteArrayInputStreamTest.java =================================================================== --- src/test/java/tests/api/java/io/ByteArrayInputStreamTest.java (revision 489636) +++ src/test/java/tests/api/java/io/ByteArrayInputStreamTest.java (working copy) @@ -17,6 +17,9 @@ package tests.api.java.io; +import java.io.ByteArrayInputStream; +import java.io.IOException; + public class ByteArrayInputStreamTest extends junit.framework.TestCase { private java.io.InputStream is; @@ -41,10 +44,11 @@ } /** + * @throws IOException * @tests java.io.ByteArrayInputStream#ByteArrayInputStream(byte[], int, * int) */ - public void test_Constructor$BII() { + public void test_Constructor$BII() throws IOException { // Test for method java.io.ByteArrayInputStream(byte [], int, int) byte[] zz = fileString.getBytes(); @@ -56,8 +60,29 @@ } catch (Exception e) { fail("Exception during Constructor test"); } + + // Regression test for Harmony-2405 + new SubByteArrayInputStream(new byte[] { 1, 2 }, 444, 13); + assertEquals(444, SubByteArrayInputStream.pos); + assertEquals(444, SubByteArrayInputStream.mark); + assertEquals(2, SubByteArrayInputStream.count); } + + static class SubByteArrayInputStream extends ByteArrayInputStream { + public static byte[] buf; + public static int mark, pos, count; + + SubByteArrayInputStream(byte[] buf, int offset, int length) + throws IOException { + super(buf, offset, length); + buf = super.buf; + mark = super.mark; + pos = super.pos; + count = super.count; + } + } + /** * @tests java.io.ByteArrayInputStream#available() */ Index: src/main/java/java/io/ByteArrayInputStream.java =================================================================== --- src/main/java/java/io/ByteArrayInputStream.java (revision 489636) +++ src/main/java/java/io/ByteArrayInputStream.java (working copy) @@ -71,10 +71,10 @@ */ public ByteArrayInputStream(byte buf[], int offset, int length) { this.buf = buf; - pos = offset >= buf.length ? buf.length : offset; - mark = pos; - count = length + pos > buf.length ? buf.length : length + pos; - } + pos = offset; + mark = offset; + count = offset + length > buf.length ? buf.length : offset + length; + } /** * Answers a int representing then number of bytes that are available before