harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r1001652 - 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 Mon, 27 Sep 2010 09:57:24 GMT
Author: odeakin
Date: Mon Sep 27 09:57:24 2010
New Revision: 1001652

URL: http://svn.apache.org/viewvc?rev=1001652&view=rev
Log:
According to the spec, String.concat() should return a new String object whenever the parameter
String length is not 0. Also add a regression test to check this.

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=1001652&r1=1001651&r2=1001652&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
Mon Sep 27 09:57:24 2010
@@ -678,14 +678,17 @@ public final class String implements Ser
      *         specified string.
      */
     public String concat(String string) {
-        if (string.count > 0 && count > 0) {
-            char[] buffer = new char[count + string.count];
+        if (string.count == 0) {
+            return this;
+        }
+
+        char[] buffer = new char[count + string.count];
+        if (count > 0) {
             System.arraycopy(value, offset, buffer, 0, count);
-            System.arraycopy(string.value, string.offset, buffer, count,
-                    string.count);
-            return new String(0, buffer.length, buffer);
         }
-        return count == 0 ? string : this;
+        System.arraycopy(string.value, string.offset, buffer, count,
+                string.count);
+        return new String(0, buffer.length, buffer);
     }
 
     /**

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=1001652&r1=1001651&r2=1001652&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
Mon Sep 27 09:57:24 2010
@@ -282,6 +282,7 @@ public class String2Test extends junit.f
         String s2 = "s2";
         String s3 = s1.concat(s2);
         assertEquals(s2, s3);
+        assertNotSame(s2, s3);
 
         s3 = s2.concat(s1);
         assertSame(s2, s3);



Mime
View raw message