You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/12/28 15:01:14 UTC

svn commit: r490730 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ByteArrayInputStream.java test/java/tests/api/java/io/ByteArrayInputStreamTest.java

Author: tellison
Date: Thu Dec 28 06:01:13 2006
New Revision: 490730

URL: http://svn.apache.org/viewvc?view=rev&rev=490730
Log:
Apply patch for HARMONY-2405 ([classlib][luni] java.io.ByteArrayInputStream wrongly sets protected pos and mark fields)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ByteArrayInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ByteArrayInputStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ByteArrayInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ByteArrayInputStream.java?view=diff&rev=490730&r1=490729&r2=490730
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ByteArrayInputStream.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ByteArrayInputStream.java Thu Dec 28 06:01:13 2006
@@ -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

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ByteArrayInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ByteArrayInputStreamTest.java?view=diff&rev=490730&r1=490729&r2=490730
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ByteArrayInputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ByteArrayInputStreamTest.java Thu Dec 28 06:01:13 2006
@@ -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();
@@ -55,6 +59,27 @@
 					100, bis.available());
 		} 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;
 		}
 	}