Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 16431 invoked from network); 31 Mar 2004 12:34:57 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 31 Mar 2004 12:34:57 -0000 Received: (qmail 73724 invoked by uid 500); 31 Mar 2004 12:34:51 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 73674 invoked by uid 500); 31 Mar 2004 12:34:51 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: dev@cocoon.apache.org Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 73647 invoked from network); 31 Mar 2004 12:34:50 -0000 Received: from unknown (HELO adina.local) (81.174.11.87) by daedalus.apache.org with SMTP; 31 Mar 2004 12:34:50 -0000 Received: from apache.org (localhost [127.0.0.1]) by adina.local (Postfix) with ESMTP id 967741D3420 for ; Wed, 31 Mar 2004 14:34:43 +0200 (CEST) Message-ID: <406ABAE3.5040408@apache.org> Date: Wed, 31 Mar 2004 14:34:43 +0200 From: Gianugo Rabellino User-Agent: Mozilla Thunderbird 0.5 (Macintosh/20040208) X-Accept-Language: en-us, en MIME-Version: 1.0 To: dev@cocoon.apache.org Subject: Re: [Kernel2.2] Remove nulls? References: <406AA2F1.5010204@apache.org> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Pier Fumagalli wrote: > On 31 Mar 2004, at 11:52, Gianugo Rabellino wrote: > >> I've seen in the new API that in a number of places there are >> contracts that return null if something isn't found: since these are >> all perfect candidates for nasty NPEs, how about switching to >> NullObject pattern or throw Exceptions instead? > > > As far as I can see, "null"s are returned only when implementing the > collections interfaces (Library, Parameters, Configuration) or when URLs > are resolved (Resolver). > > And even there (ex. Configuration and Parameters) when calling a method > specifed in the interface, and not inherited from the > Set/Map/Collection, it will throw specific exceptions (ex. > ConfigurationException). > > Where did you notice it? Well... there are 10 occurrences, but this are the most prominent: o.a.c.kernel.configuration.Parameters.java: public Object get(Object name) { if (name == null) return(null); o.a.c.kernel.archival.HashLibrary.java: public Descriptor get(Identifier identifier) { if (this.contains(identifier)) { Iterator iterator = this.iterator(); while (iterator.hasNext()) { Descriptor descriptor = (Descriptor) iterator.next(); if (descriptor.equals(identifier)) return(descriptor); } } return(null); } o.a.c.kernel.resolution.CompoundResolver.java: public Resource resolve(String name) { Resolver r[] = (Resolver[])list.toArray(new Resolver[list.size()]); for (int x = 0; x < r.length; x ++) { Resource s = r[x].resolve(name); if (s != null) return(s); } return(null); } I haven't been through the code to see what exactly these things do, but from a pure OOP POV (whatever that means :-)) there is some "code that smells" (http://c2.com/cgi/wiki?CodeSmell). It might make sense, but in most cases it doesn't. Ciao, -- Gianugo Rabellino Pro-netics s.r.l. - http://www.pro-netics.com Orixo, the XML business alliance - http://www.orixo.com (Blogging at: http://www.rabellino.it/blog/)