Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 3354 invoked from network); 9 Apr 2009 10:43:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 9 Apr 2009 10:43:56 -0000 Received: (qmail 76784 invoked by uid 500); 9 Apr 2009 10:43:55 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 76669 invoked by uid 500); 9 Apr 2009 10:43:55 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 76659 invoked by uid 99); 9 Apr 2009 10:43:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Apr 2009 10:43:55 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.219.160] (HELO mail-ew0-f160.google.com) (209.85.219.160) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Apr 2009 10:43:48 +0000 Received: by ewy4 with SMTP id 4so701574ewy.42 for ; Thu, 09 Apr 2009 03:43:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.21.194 with SMTP id r44mr580546wer.80.1239273806194; Thu, 09 Apr 2009 03:43:26 -0700 (PDT) In-Reply-To: <31cc37360904090143x43975f41qecf40d4f6bbdeef5@mail.gmail.com> References: <31cc37360904090143x43975f41qecf40d4f6bbdeef5@mail.gmail.com> From: James Carman Date: Thu, 9 Apr 2009 06:43:11 -0400 Message-ID: Subject: Re: [LANG] Null-protection methods To: Commons Developers List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On Thu, Apr 9, 2009 at 4:43 AM, Henri Yandell wrote: > Is the following worth keeping in Lang? > > public Foo someJdkMethod(Object input) { > =A0 =A0if(input =3D=3D null) { > =A0 =A0 =A0 =A0handleAccordingly(); > =A0 =A0} > =A0 =A0return input.jdkMethod(); > } > > I feel that we've bloated up with these methods, and is it really > worth it? I still have lots of if(x !=3D null && x.callFoo()) type > invocations, having a small handful of methods available in Lang to > let me say if(FooUtils.callFoo(x)) isn't enough to hide all of the > other times when I might have to worry about it. > > Personally I'd like to see these methods removed from Lang [especially > given Stephen's blogging about null protected setting in some future > JVM]. > > An example: > > =A0 =A0public static String trim(String str) { > =A0 =A0 =A0 =A0return str =3D=3D null ? null : str.trim(); > =A0 =A0} > > Given that I'm likely to do N things to the string, chances are I'll > check for null up front and then invoke methods rather than repeatedly > writing ugly code by using StringUtils. > > Any thoughts in favour of these methods? What do bug catchers such as FindBugs do with situations like these? Would they still report it as a potential bug? Or, do they dig into the FooUtils.callFoo() methods to see if they're doing the null check? I'm just curious, I guess. If FindBugs is still going to report it as a potential bug, then it would seem like folks would probably be doing the null check on their own to quiet down FindBugs (not that everyone uses it of course). --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org