Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 3840 invoked from network); 16 Jan 2010 08:09:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 16 Jan 2010 08:09:18 -0000 Received: (qmail 64619 invoked by uid 500); 16 Jan 2010 08:09:17 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 64527 invoked by uid 500); 16 Jan 2010 08:09:17 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 64517 invoked by uid 99); 16 Jan 2010 08:09:17 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Jan 2010 08:09:17 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Jan 2010 08:09:15 +0000 Received: from brutus.apache.org (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 86739234C495 for ; Sat, 16 Jan 2010 00:08:54 -0800 (PST) Message-ID: <1732635416.288111263629334549.JavaMail.jira@brutus.apache.org> Date: Sat, 16 Jan 2010 08:08:54 +0000 (UTC) From: "Henri Yandell (JIRA)" To: issues@commons.apache.org Subject: [jira] Commented: (LANG-571) ArrayUtils.add(T[] array, T element) can create unexpected ClassCastException In-Reply-To: <19939374.1261111218108.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ 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.