Propagate original exception (LANG-567); update docs
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@892326 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e5ccf09656
commit
352a4ef2a3
|
@ -2950,6 +2950,7 @@ public class ArrayUtils {
|
|||
* 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 @@ public class ArrayUtils {
|
|||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue