harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r954798 - in /harmony/enhanced/java/trunk/classlib/modules/luni/src: main/java/java/lang/String.java test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
Date Tue, 15 Jun 2010 10:38:35 GMT
Author: tellison
Date: Tue Jun 15 10:38:34 2010
New Revision: 954798

URL: http://svn.apache.org/viewvc?rev=954798&view=rev
Log:
Apply patch for HARMONY-6502 ([classlib][luni] String.substring does not throw StringIndexOutOfBoundsException
with index)

Modified:
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/lang/String.java
    harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/lang/String.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/lang/String.java?rev=954798&r1=954797&r2=954798&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/lang/String.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/lang/String.java
Tue Jun 15 10:38:34 2010
@@ -1418,12 +1418,15 @@ public final class String implements Ser
         if (start == 0 && end == count) {
             return this;
         }
-        // NOTE last character not copied!
-        // Fast range check.
-        if (0 <= start && start <= end && end <= count) {
-            return new String(offset + start, end - start, value);
+        if (start < 0) {
+            throw new StringIndexOutOfBoundsException(start);
+        } else if (start > end) {
+            throw new StringIndexOutOfBoundsException(end - start);
+        } else if (end > count) {
+            throw new StringIndexOutOfBoundsException(end);
         }
-        throw new StringIndexOutOfBoundsException();
+        // NOTE last character not copied!
+        return new String(offset + start, end - start, value);
     }
 
     /**

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java?rev=954798&r1=954797&r2=954798&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
Tue Jun 15 10:38:34 2010
@@ -743,6 +743,33 @@ public class String2Test extends junit.f
                 && (hw1.substring(5, 10).equals("World")));
         assertTrue("not identical", hw1.substring(0, hw1.length()) == hw1);
     }
+    
+	/**
+	 * @tests java.lang.String#substring(int, int)
+	 */
+	public void test_substringErrorMessage() {
+		try {
+			hw1.substring(-1, 1);
+		} catch (StringIndexOutOfBoundsException ex) {
+			String msg = ex.getMessage();
+			assertTrue("Expected message to contain -1: " + msg, msg
+			        .indexOf("-1") != -1);
+		}
+		try {
+			hw1.substring(4, 1);
+		} catch (StringIndexOutOfBoundsException ex) {
+			String msg = ex.getMessage();
+			assertTrue("Expected message to contain -3: " + msg, msg
+			        .indexOf("-3") != -1);
+		}
+		try {
+			hw1.substring(0, 100);
+		} catch (StringIndexOutOfBoundsException ex) {
+			String msg = ex.getMessage();
+			assertTrue("Expected message to contain 100: " + msg, msg
+			        .indexOf("100") != -1);
+		}
+	}
 
     /**
      * @tests java.lang.String#toCharArray()



Mime
View raw message