commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Commented: (LANG-571) ArrayUtils.add(T[] array, T element) can create unexpected ClassCastException
Date Sat, 16 Jan 2010 08:08:54 GMT

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

Henri Yandell commented on LANG-571:
------------------------------------

Assuming you mean IllegalArgumentException, +1.

> 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.


Mime
View raw message