commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r904079 - /commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ArrayUtils.java
Date Thu, 28 Jan 2010 13:28:05 GMT
Author: niallp
Date: Thu Jan 28 13:28:04 2010
New Revision: 904079

URL: http://svn.apache.org/viewvc?rev=904079&view=rev
Log:
Reformatting & javadoc changes only

Modified:
    commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ArrayUtils.java

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ArrayUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ArrayUtils.java?rev=904079&r1=904078&r2=904079&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ArrayUtils.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ArrayUtils.java
Thu Jan 28 13:28:04 2010
@@ -3230,7 +3230,8 @@
      * the new array is the same as that of the input array.</p>
      *
      * <p>If the input array is <code>null</code>, a new one element array
is returned
-     *  whose component type is the same as the element.</p>
+     *  whose component type is the same as the element, unless the element itself is null,
+     *  in which case the return type is Object[]</p>
      *
      * <pre>
      * ArrayUtils.add(null, null)      = [null]
@@ -3241,12 +3242,21 @@
      * </pre>
      *
      * @param array  the array to "add" the element to, may be <code>null</code>
-     * @param element  the object to add
+     * @param element  the object to add, may be <code>null</code>
      * @return A new array containing the existing elements plus the new element
+     * The returned array type will be that of the input array (unless null),
+     * in which case it will have the same type as the element.
      * @since 2.1
      */
     public static Object[] add(Object[] array, Object element) {
-        Class type = array != null ? array.getClass() : (element != null ? element.getClass()
: Object.class);
+        Class type;
+        if (array != null){
+            type = array.getClass();
+        } else if (element != null) {
+            type = element.getClass();
+        } else {
+            type = Object.class;
+        }
         Object[] newArray = (Object[]) copyArrayGrow1(array, type);
         newArray[newArray.length - 1] = element;
         return newArray;



Mime
View raw message