harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r448771 - in /incubator/harmony/enhanced/classlib/trunk/modules/text/src: main/java/java/text/BreakIterator.java test/java/org/apache/harmony/text/tests/java/text/BreakIteratorTest.java
Date Fri, 22 Sep 2006 02:22:00 GMT
Author: pyang
Date: Thu Sep 21 19:21:59 2006
New Revision: 448771

URL: http://svn.apache.org/viewvc?view=rev&rev=448771
Log:
Apply updated patch for HARMONY-944 ([classlib][text] java.text.BreakIterator.getInt(byte[],
Integer.MAX_VALUE) does not throw ArrayIndexOutOfBoundsException)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/BreakIterator.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/BreakIteratorTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/BreakIterator.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/BreakIterator.java?view=diff&rev=448771&r1=448770&r2=448771
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/BreakIterator.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/BreakIterator.java
Thu Sep 21 19:21:59 2006
@@ -1,4 +1,4 @@
-/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2005, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -393,7 +393,7 @@
 		if(null == buf){
 			throw new NullPointerException();
 		}
-		if(offset < 0 || offset + LONG_LENGTH > buf.length){
+		if(offset < 0 || buf.length - offset < LONG_LENGTH){
 			throw new ArrayIndexOutOfBoundsException();
 		}
 		long result = 0;
@@ -414,7 +414,7 @@
 		if(null == buf){
 			throw new NullPointerException();
 		}
-		if(offset < 0 || offset + INT_LENGTH > buf.length){
+		if(offset < 0 || buf.length - INT_LENGTH < offset){
 			throw new ArrayIndexOutOfBoundsException();
 		}
 		int result = 0;
@@ -431,11 +431,11 @@
 	 * @param offset	the start position of conversion
 	 * @return	the converted short value
 	 */
-	protected static short getShort(byte[] buf, int offset) {
+	protected static short getShort(byte[] buf, int offset) {        
 		if(null == buf){
 			throw new NullPointerException();
 		}
-		if(offset < 0 || offset + SHORT_LENGTH > buf.length){
+		if(offset < 0 || buf.length - SHORT_LENGTH < offset){
 			throw new ArrayIndexOutOfBoundsException();
 		}
 		short result = 0;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/BreakIteratorTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/BreakIteratorTest.java?view=diff&rev=448771&r1=448770&r2=448771
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/BreakIteratorTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/BreakIteratorTest.java
Thu Sep 21 19:21:59 2006
@@ -288,6 +288,10 @@
         assertEquals(2, iterator.next());
 	}
 
+    /**
+     * @tests java.text.BreakIterator.getShort(byte[], int)
+     * 
+     */
 	public void test_getShort() {
 		try {
 			MockBreakIterator.publicGetShort(null, 0);
@@ -316,8 +320,29 @@
 		assertEquals(1, MockBreakIterator.publicGetShort(new byte[] { 0, 0, 1, 0 }, 1));
 		assertEquals(1, MockBreakIterator.publicGetShort(new byte[] { 0, 0, 1, 1 }, 1));
 		assertEquals(257, MockBreakIterator.publicGetShort(new byte[] { 0, 1, 1 }, 1));
+        
+        // regression for Harmony-944
+        try {
+            MockBreakIterator.publicGetShort(new byte[] { 0, 0 },
+                    Integer.MAX_VALUE);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            MockBreakIterator.publicGetShort(new byte[] { 0, 0 },
+                    Short.MAX_VALUE);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            //expected
+        }
 	}
 	
+    /**
+     * @tests java.text.BreakIterator.getInt(byte[], int)
+     * 
+     */
 	public void test_getInt() {
 		try {
 			MockBreakIterator.publicGetInt(null, 0);
@@ -346,8 +371,21 @@
 		assertEquals(1, MockBreakIterator.publicGetInt(new byte[] { 0, 0, 0, 0, 1, 0 }, 1));
 		assertEquals(1, MockBreakIterator.publicGetInt(new byte[] { 0, 0, 0, 0, 1, 1 }, 1));
 		assertEquals(257, MockBreakIterator.publicGetInt(new byte[] { 0, 0, 0, 1, 1 }, 1));
+        
+        // regression for Harmony-944
+        try {
+            MockBreakIterator.publicGetInt(new byte[] { 0, 0 },
+                    Integer.MAX_VALUE);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
 	}
 	
+    /**
+     * @tests java.text.BreakIterator.getLong(byte[], int)
+     * 
+     */
 	public void test_getLong() {
 		try {
 			MockBreakIterator.publicGetLong(null, 0);
@@ -376,6 +414,15 @@
 		assertEquals(1, MockBreakIterator.publicGetLong(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 1,
0 }, 1));
 		assertEquals(1, MockBreakIterator.publicGetLong(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 1,
1 }, 1));
 		assertEquals(257, MockBreakIterator.publicGetLong(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1,
1 }, 1));
+        
+        // regression for Harmony-944
+        try {
+            MockBreakIterator.publicGetLong(new byte[] { 0, 1 },
+                    Integer.MAX_VALUE);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
 	}
     
 	/**



Mime
View raw message