commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang ArrayUtils.java
Date Tue, 16 Mar 2004 01:40:58 GMT
ggregory    2004/03/15 17:40:58

  Modified:    lang/src/test/org/apache/commons/lang ArrayUtilsAddTest.java
               lang/src/java/org/apache/commons/lang ArrayUtils.java
  Log:
  
  PR: Bugzilla Bug 27661 [lang] [patch] ArrayUtils.addAll doesn't always return new array
  Submitted by:	Maarten Coene
  Reviewed by:	
Gary Gregory
  
  Revision  Changes    Path
  1.3       +3 -1      jakarta-commons/lang/src/test/org/apache/commons/lang/ArrayUtilsAddTest.java
  
  Index: ArrayUtilsAddTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/ArrayUtilsAddTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ArrayUtilsAddTest.java	18 Feb 2004 23:06:19 -0000	1.2
  +++ ArrayUtilsAddTest.java	16 Mar 2004 01:40:57 -0000	1.3
  @@ -197,10 +197,12 @@
           String[] stringArray1 = new String[]{"a", "b", "c"};
           String[] stringArray2 = new String[]{"1", "2", "3"};
           newArray = ArrayUtils.addAll(stringArray1, null);
  +        assertNotSame(stringArray1, newArray);
           assertTrue(Arrays.equals(stringArray1, newArray));
           assertTrue(Arrays.equals((new String[]{"a", "b", "c"}), newArray));
           assertEquals(String.class, newArray.getClass().getComponentType());
           newArray = ArrayUtils.addAll(null, stringArray2);
  +        assertNotSame(stringArray2, newArray);
           assertTrue(Arrays.equals(stringArray2, newArray));
           assertTrue(Arrays.equals((new String[]{"1", "2", "3"}), newArray));
           assertEquals(String.class, newArray.getClass().getComponentType());
  
  
  
  1.43      +7 -6      jakarta-commons/lang/src/java/org/apache/commons/lang/ArrayUtils.java
  
  Index: ArrayUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/ArrayUtils.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- ArrayUtils.java	18 Feb 2004 22:59:50 -0000	1.42
  +++ ArrayUtils.java	16 Mar 2004 01:40:57 -0000	1.43
  @@ -2768,12 +2768,13 @@
       /**
        * <p>Adds all the elements of the provided arrays into a new array.</p>
        * <p>The new array contains all of the element of <code>array1</code>
followed
  -     * by all of the elements <code>array2</code>.</p>
  +     * by all of the elements <code>array2</code>. If an array is returned,
it is always
  +     * a new array.</p>
        *
        * <pre>
        * ArrayUtils.addAll(null, null)     = null
  -     * ArrayUtils.addAll(array1, null)   = array1
  -     * ArrayUtils.addAll(null, array2)   = array2
  +     * ArrayUtils.addAll(array1, null)   = cloned copy of array1
  +     * ArrayUtils.addAll(null, array2)   = cloned copy of array2
        * ArrayUtils.addAll([], [])         = []
        * ArrayUtils.addAll([null], [null]) = [null, null]
        * ArrayUtils.addAll(["a", "b", "c"], ["1", "2", "3"]) = ["a", "b", "c", "1", "2",
"3"]
  @@ -2787,9 +2788,9 @@
        */
       public static Object[] addAll(Object[] array1, Object[] array2) {
           if (array1 == null) {
  -            return array2;
  +            return clone(array2);
           } else if (array2 == null) {
  -            return array1;
  +            return clone(array1);
           } else {
               Object[] joinedArray = (Object[]) Array.newInstance(array1.getClass().getComponentType(),
array1.length
                   + array2.length);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message