[ 
https://issues.apache.org/jira/browse/LANG-567?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Sebb updated LANG-567:
----------------------

    Description: 
ArrayUtils.addAll(T[] array1, T... array2) does not handle mixed array types 
very well.

The stack trace for 

Number[] st = ArrayUtils.addAll(new Integer[]{1}, new Long[]{2L});

starts:

java.lang.ArrayStoreException
        at java.lang.System.arraycopy(Native Method)
        at org.apache.commons.lang3.ArrayUtils.addAll(ArrayUtils.java:2962)

which is not all that obvious.

It would be a lot clearer if the method threw an IlegalArgumentException or 
similar.

  was:
ArrayUtils.addAll(T[] array1, T... array2) does not handle mixed array types 
very well.

The stack trace for ArrayUtils.addAll(stringArray1, new Object()) starts:

java.lang.ArrayStoreException
        at java.lang.System.arraycopy(Native Method)
        at org.apache.commons.lang3.ArrayUtils.addAll(ArrayUtils.java:2962)

which is not all that obvious.

Unfortunately the type parameters aren't checked (because the method is static) 
unless one uses:

ArrayUtils.<String>addAll(stringArray1, new Object())

which it seems unlikely anyone would use.

Might be better just to use Object and check the types at run-time?


Better example

> ArrayUtils.addAll(T[] array1, T... array2) does not handle mixed types very 
> well
> --------------------------------------------------------------------------------
>
>                 Key: LANG-567
>                 URL: https://issues.apache.org/jira/browse/LANG-567
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>            Reporter: Sebb
>             Fix For: 3.0
>
>
> ArrayUtils.addAll(T[] array1, T... array2) does not handle mixed array types 
> very well.
> The stack trace for 
> Number[] st = ArrayUtils.addAll(new Integer[]{1}, new Long[]{2L});
> starts:
> java.lang.ArrayStoreException
>       at java.lang.System.arraycopy(Native Method)
>       at org.apache.commons.lang3.ArrayUtils.addAll(ArrayUtils.java:2962)
> which is not all that obvious.
> It would be a lot clearer if the method threw an IlegalArgumentException or 
> similar.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to