harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghar...@apache.org
Subject svn commit: r406614 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/lang/ test/java/org/apache/harmony/tests/java/lang/
Date Mon, 15 May 2006 11:06:33 GMT
Author: gharley
Date: Mon May 15 04:06:31 2006
New Revision: 406614

URL: http://svn.apache.org/viewcvs?rev=406614&view=rev
Log:
HARMONY 436 : Harmony should throw exceptions in a way similar to RI's one

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StringBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StringBuilder.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBufferTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBuilderTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StringBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StringBuffer.java?rev=406614&r1=406613&r2=406614&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StringBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StringBuffer.java
Mon May 15 04:06:31 2006
@@ -145,13 +145,16 @@
 	 *            the number of characters
 	 * @return this StringBuffer
 	 * 
-	 * @exception IndexOutOfBoundsException
+	 * @exception ArrayIndexOutOfBoundsException
 	 *                when <code>length < 0, start < 0</code> or
 	 *                <code>start + length > chars.length</code>
 	 * @exception NullPointerException
 	 *                when chars is null
 	 */
 	public synchronized StringBuffer append(char chars[], int start, int length) {
+        if (chars == null) {
+            throw new NullPointerException();
+        }
 		// start + length could overflow, start/length maybe MaxInt
 		if (start >= 0 && 0 <= length && length <= chars.length - start)
{
 			int newSize = count + length;
@@ -165,7 +168,7 @@
 			count = newSize;
 			return this;
 		}
-		throw new StringIndexOutOfBoundsException();
+		throw new ArrayIndexOutOfBoundsException();
 	}
 
 	/**
@@ -448,7 +451,7 @@
 			}
 		} catch (IndexOutOfBoundsException e) {
 		}
-		throw new StringIndexOutOfBoundsException();
+		throw new ArrayIndexOutOfBoundsException();
 	}
 
 	/**
@@ -521,7 +524,7 @@
 	 *            the character to insert
 	 * @return this StringBuffer
 	 * 
-	 * @exception IndexOutOfBoundsException
+	 * @exception ArrayIndexOutOfBoundsException
 	 *                when <code>index < 0</code> or
 	 *                <code>index > length()</code>
 	 */
@@ -532,7 +535,7 @@
 			count++;
 			return this;
 		}
-		throw new StringIndexOutOfBoundsException(index);
+		throw new ArrayIndexOutOfBoundsException(index);
 	}
 
 	/**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StringBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StringBuilder.java?rev=406614&r1=406613&r2=406614&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StringBuilder.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StringBuilder.java
Mon May 15 04:06:31 2006
@@ -642,14 +642,14 @@
      * @param c The <code>char</code> value to insert into this object.
      * @return A reference to this object.
      * 
-     * @throws StringIndexOutOfBoundsException if <code>offset</code> is
+     * @throws ArrayIndexOutOfBoundsException if <code>offset</code> is
      *         negative or greater than the current {@link #length()}.
      * 
      * @see String#valueOf(char)
      */
     public StringBuilder insert(int offset, char c) {
         if (offset < 0 || offset > length)
-            throw new StringIndexOutOfBoundsException();
+            throw new ArrayIndexOutOfBoundsException();
 
         return insert(offset, String.valueOf(c));
     }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBufferTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBufferTest.java?rev=406614&r1=406613&r2=406614&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBufferTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBufferTest.java
Mon May 15 04:06:31 2006
@@ -94,6 +94,36 @@
     }
     
     /**
+     * @tests java.lang.StringBuffer.append(char[], int, int)
+     */
+    public void test_append$CII_2() {
+        StringBuffer obj = new StringBuffer();
+        try {
+            obj.append(new char[0], (int) -1, (int) -1);
+            fail("ArrayIndexOutOfBoundsException expected");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests java.lang.StringBuffer.append(char[], int, int)
+     */
+    public void test_append$CII_3() throws Exception {
+        StringBuffer obj = new StringBuffer();
+        try {
+            obj.append((char[]) null, (int) -1, (int) -1);
+            fail("NullPointerException expected");
+        } catch (NullPointerException e) {
+            // expected
+        } catch (Exception e) {
+            assertEquals(
+                    "NullPointerException expected",
+                    NullPointerException.class, e.getClass());
+        }
+    }
+
+    /**
      * @tests java.lang.StringBuffer.insert(int, CharSequence)
      */
     public void test_insertILjava_lang_CharSequence() {
@@ -217,6 +247,19 @@
     }
     
     /**
+     * @tests java.lang.StringBuffer.insert(int, char)
+     */
+    public void test_insertIC() {
+        StringBuffer obj = new StringBuffer();
+        try {
+            obj.insert((int) -1, ' ');
+            fail("ArrayIndexOutOfBoundsException expected");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
+    }
+
+    /**
      * @tests java.lang.StringBuffer.appendCodePoint(int)'
      */
     public void test_appendCodePointI() {
@@ -334,6 +377,19 @@
         }
     }
     
+    /**
+     * @tests java.lang.StringBuffer.getChars(int, int, char[], int)
+     */
+    public void test_getCharsII$CI() {
+        StringBuffer obj = new StringBuffer();
+        try {
+            obj.getChars((int) 0, (int) 0,  new char[0], (int) -1);
+            fail("ArrayIndexOutOfBoundsException expected");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
+    }
+
     /**
      * @tests java.lang.StringBuffer.offsetByCodePoints(int, int)'
      */

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBuilderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBuilderTest.java?rev=406614&r1=406613&r2=406614&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBuilderTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBuilderTest.java
Mon May 15 04:06:31 2006
@@ -832,7 +832,20 @@
 //		}
 	}
 
-	/**
+    /**
+     * @tests java.lang.StringBuilder.insert(int, char)
+     */
+    public void test_insertIC_2() {
+        StringBuilder obj = new StringBuilder();
+        try {
+            obj.insert((int) -1, '?');
+            fail("ArrayIndexOutOfBoundsException expected");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
+    }
+
+    /**
 	 * @tests java.lang.StringBuilder.insert(int, char[])'
 	 */
 	public void test_insertI$C() {



Mime
View raw message