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 E0D02200CAD for ; Wed, 28 Jun 2017 12:06:13 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id DF1A4160BF7; Wed, 28 Jun 2017 10:06:13 +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 2FAD2160BE8 for ; Wed, 28 Jun 2017 12:06:13 +0200 (CEST) Received: (qmail 38481 invoked by uid 500); 28 Jun 2017 10:06:07 -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 38469 invoked by uid 99); 28 Jun 2017 10:06:07 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Jun 2017 10:06:07 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id CF8C7C1FB5 for ; Wed, 28 Jun 2017 10:06:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.211 X-Spam-Level: X-Spam-Status: No, score=-99.211 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id XOrdVI_XLAA4 for ; Wed, 28 Jun 2017 10:06:05 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id AA8545FC4D for ; Wed, 28 Jun 2017 10:06:04 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 62C5CE0D7F for ; Wed, 28 Jun 2017 10:06:03 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 8B45D2416D for ; Wed, 28 Jun 2017 10:06:01 +0000 (UTC) Date: Wed, 28 Jun 2017 10:06:01 +0000 (UTC) From: "Jonas Holtkamp (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (COLLECTIONS-604) More uniform safe-null methods in CollectionUtils MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 28 Jun 2017 10:06:14 -0000 [ https://issues.apache.org/jira/browse/COLLECTIONS-604?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16066266#comment-16066266 ] Jonas Holtkamp commented on COLLECTIONS-604: -------------------------------------------- [~kinow] No feedback from his side, so I'd start implementing some example cases on the weekend. > More uniform safe-null methods in CollectionUtils > ------------------------------------------------- > > Key: COLLECTIONS-604 > URL: https://issues.apache.org/jira/browse/COLLECTIONS-604 > Project: Commons Collections > Issue Type: Bug > Components: Collection > Affects Versions: 4.1 > Reporter: Bruno P. Kinoshita > Assignee: Bruno P. Kinoshita > Priority: Minor > Attachments: COLLECTIONS-604.csv > > > Currently, there are 65 public methods in `CollectionUtils`. And 53 without the deprecated ones. Out of these, 24 handle `null` arguments. The remaining methods throw a `NullPointerException` (NPE) at some part of its code. > The methods that handle nulls, throw NPE, or return empty columns, boolean values, or just doesn't do anything. > As a user of the API, I would expect a more uniform behaviour across the methods of `CollectionUtils`. COLLECTIONS-600 address one of these methods. > `removeAll` (2x) and `retainAll` (2x) both state that a NPE will be thrown if either parameter is `null`. However, they never check if the values are null, and instead allow the code to run until a NPE is thrown. > And the following code shows that `isEmpty` and `isFull` behave differently too. > {code:java} > Collection c = null; > System.out.println(CollectionUtils.isEmpty(c)); // return true > System.out.println(CollectionUtils.isFull(c)); // throws a NPE > {code} > If I don't have to worry about `null`s with `#isEmpty`, I would expect the same from its related-method `#isFull`. > What would be a good approach for it? Define a behaviour to all methods? Or leave as is, but add more documentation? > There are a few methods that can easily be updated to check for `null` values. Others would require a bit more thinking. An example if the method in question for COLLECTIONS-600. It checks equality of collections, and when both collections are `null`, it says that they are equals. Google Guava [Iterables#elementsEqual|https://github.com/google/guava/blob/312aeb938bd35b5b7c8930e19ff5d1ca38e49424/guava/src/com/google/common/collect/Iterables.java#L232] and [Iterators#elementsEqual|https://github.com/google/guava/blob/312aeb938bd35b5b7c8930e19ff5d1ca38e49424/guava/src/com/google/common/collect/Iterators.java#L274] do not check for null values, for what it is worth. -- This message was sent by Atlassian JIRA (v6.4.14#64029)