Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 207BE200BDB for ; Mon, 12 Dec 2016 23:49:00 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 1F32D160B30; Mon, 12 Dec 2016 22:49:00 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 68C4E160B1A for ; Mon, 12 Dec 2016 23:48:59 +0100 (CET) Received: (qmail 16549 invoked by uid 500); 12 Dec 2016 22:48:58 -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 16520 invoked by uid 99); 12 Dec 2016 22:48:58 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Dec 2016 22:48:58 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 70D502C03DD for ; Mon, 12 Dec 2016 22:48:58 +0000 (UTC) Date: Mon, 12 Dec 2016 22:48:58 +0000 (UTC) From: "Pascal Schumacher (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (LANG-1296) ArrayUtils.addAll() has unsafe use of varargs MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 12 Dec 2016 22:49:00 -0000 [ https://issues.apache.org/jira/browse/LANG-1296?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15743411#comment-15743411 ] Pascal Schumacher commented on LANG-1296: ----------------------------------------- A version of commons-lang containing this method with the @SafeVarargs annotation has not been release yet, so it can just be removed. > ArrayUtils.addAll() has unsafe use of varargs > --------------------------------------------- > > Key: LANG-1296 > URL: https://issues.apache.org/jira/browse/LANG-1296 > Project: Commons Lang > Issue Type: Bug > Components: lang.* > Affects Versions: 3.5 > Reporter: Duncan Jones > Priority: Critical > > {{ArrayUtils.addAll()}} is marked as {{@SafeVarargs}}, but I suspect the use of the varargs is unsafe. > An example, drawn heavily from [this StackOverflow answer|http://stackoverflow.com/a/14252221/474189], demonstrates this: > {code:java} > static T[] arrayOfTwo(T a, T b) { > return ArrayUtils.addAll(null, a, b); > } > @Test > public void testBadVarArgs() throws Exception { > @SuppressWarnings("unused") // Need to assign to trigger exception > String[] result = arrayOfTwo("foo", "bar"); > } > {code} > the above code throws an exception: {{java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;}}. > Here, the {{null}} input array causes the method to return a clone of the vararg array. This is what triggers the problem. > I faced a similar issue when adding the {{ArrayUtils.insert(...)}} methods and I solved it by returning {{null}} if the input array is {{null}}. We can't do this here without breaking behaviour. -- This message was sent by Atlassian JIRA (v6.3.4#6332)