You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Sebb (JIRA)" <ji...@apache.org> on 2009/12/18 06:06:18 UTC

[jira] Commented: (LANG-571) ArrayUtils.add(T[] array, T element) can create unexpected ClassCastException

    [ https://issues.apache.org/jira/browse/LANG-571?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12792344#action_12792344 ] 

Sebb commented on LANG-571:
---------------------------

The same comments apply to the method ArrayUtils.add(T[] array, int index, T element)



> ArrayUtils.add(T[] array, T element) can create unexpected ClassCastException
> -----------------------------------------------------------------------------
>
>                 Key: LANG-571
>                 URL: https://issues.apache.org/jira/browse/LANG-571
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>            Reporter: Sebb
>             Fix For: 3.0
>
>
> ArrayUtils.add(T[] array, T element) can create an unexpected ClassCastException.
> For example, the following code compiles without a warning:
> {code}
> String[] sa = ArrayUtils.add(stringArray, aString);
> {code}
> and works fine, provided at least one of the parameters is non-null. However, if both parameters are null, the add() method returns an Object[] array, hence the Exception.
> If both parameters are null, it's not possible to determine the correct array type to return, so it seems to me this should be disallowed.
> I think the method ought to be changed to throw IllegalParameterException when both parameters are null.

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