commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r892326 - /commons/proper/lang/trunk/src/java/org/apache/commons/lang3/ArrayUtils.java
Date Fri, 18 Dec 2009 18:02:11 GMT
Author: sebb
Date: Fri Dec 18 18:02:11 2009
New Revision: 892326

URL: http://svn.apache.org/viewvc?rev=892326&view=rev
Log:
Propagate original exception (LANG-567); update docs

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang3/ArrayUtils.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang3/ArrayUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang3/ArrayUtils.java?rev=892326&r1=892325&r2=892326&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang3/ArrayUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang3/ArrayUtils.java Fri Dec 18
18:02:11 2009
@@ -2950,6 +2950,7 @@
      *      The type of the new array is the type of the first array,
      *      unless the first array is null, in which case the type is the same as the second
array.
      * @since 2.1
+     * @throws IllegalArgumentException if the array types are incompatible
      */
     public static <T> T[] addAll(T[] array1, T... array2) {
         if (array1 == null) {
@@ -2964,10 +2965,15 @@
         try {
             System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
         } catch (ArrayStoreException ase) {
-            // Check if problem is incompatible types
+            // Check if problem was due to incompatible types
+            /*
+             * We do this here, rather than before the copy because:
+             * - it would be a wasted check most of the time
+             * - safer, in case check turns out to be too strict
+             */
             final Class<?> type2 = array2.getClass().getComponentType();
             if (!type1.isAssignableFrom(type2)){
-                throw new IllegalArgumentException("Cannot store "+type2.getName()+" in an
array of "+type1.getName());
+                throw new IllegalArgumentException("Cannot store "+type2.getName()+" in an
array of "+type1.getName(), ase);
             }
             throw ase; // No, so rethrow original
         }



Mime
View raw message