commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <j...@apache.org>
Subject [jira] Created: (LANG-571) ArrayUtils.add(T[] array, T element) can create unexpected ClassCastException
Date Fri, 18 Dec 2009 04:40:18 GMT
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