Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 55487 invoked from network); 26 Sep 2002 18:58:49 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 26 Sep 2002 18:58:49 -0000 Received: (qmail 26582 invoked by uid 97); 26 Sep 2002 18:59:26 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 26390 invoked by uid 97); 26 Sep 2002 18:59:24 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 26273 invoked by uid 98); 26 Sep 2002 18:59:23 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Content-Type: text/plain; charset="iso-8859-1" From: Steve Downey To: "Jakarta Commons Developers List" Subject: Re: [lang] StringUtils.containsOnly Date: Thu, 26 Sep 2002 14:55:39 -0400 User-Agent: KMail/1.4.1 References: <006601c26580$bdcdde00$d55d22d9@oemcomputer> <3D9342AB.8090603@apache.org> In-Reply-To: <3D9342AB.8090603@apache.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200209261455.39747.steve.downey@netfolio.com> X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N On Thursday 26 September 2002 01:23 pm, Berin Loritsch wrote: > Stephen Colebourne wrote: > > I go further than this - in my world a product like [lang] would neve= r > > throw NPEs. If it did then that would be a bug. If null is a disallow= ed > > parameter then that should be checked and thrown as an > > IllegalArgumentException. But thats just my coding style. > > > > Its probably a pity that we didn't agree a uniform approach to this, = but > > its too late now. The priority is to document what we have correctly. > > > > Stephen > > I have to agree with you on both of your points Stephen. NPE's are > indicative of something terribly wrong. To me it is the Java equivalen= t > of the C++ pointer error. At least with an IllegalArgumentException, > you know you skrewed up using the method. An NPE could mean anything > from an illegal argument (see, IllegalArgumentException) to the method > is just completely foo-barred. I reserve NPEs for things that are > foo-barred and IllegalArgumentExceptions for wrong arguments. Well, I agree with you, Berin, and disagree with Stephen, I think.=20 As I understand it, Stephen is arguing that StringUtils should never thro= w a=20 runtime exception when presented with null. I'm arguing that it should. T= he=20 runtime exception that java.lang.String throws in similar situations is N= PE.=20 IllegalArgumentException is starting to be adopted by other parts of the = API=20 for null arguments, eg JAXP, however. It was originally used for exceptio= ns=20 like undefined locale, or where an int is used as an enum and the argumen= t=20 wasn't one of the defined enums. If it is a case of arg =3D=3D null, that can make sense. However, checkin= g every=20 object before access for being =3D=3D to null, and converting that to a d= ifferent=20 exception leads to messy code.=20 I don't like treating null as "", which is the common 'solution' to avoid= ing=20 NPEs. For example, in StringUtils.center(String str, int size), which emb= eds=20 str in the center of a string of length size, right now you get an NPE if= you=20 call StringUtils.center(null, 80). You shouldn't ever call the method wit= h=20 null. It's not meaningful. I wouldn't like to see it return a string with= 80=20 spaces. -- To unsubscribe, e-mail: For additional commands, e-mail: