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.