avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Donald <dona...@apache.org>
Subject Re: Configuration getChild() never returns null
Date Sat, 10 Nov 2001 10:23:25 GMT
On Sat, 10 Nov 2001 21:22, Jeff Turner wrote:
> Hi,
>
> The javadocs for Configuration state:
>
>   "The contract surrounding the Configuration is that once it is
>   created, information never changes."
>
> There are two variants of getChild:
>
> Configuration getChild(java.lang.String child)
> Configuration getChild(java.lang.String child, boolean createNew);
>
> Now I'm wondering, what's the "createNew" attribute for? Why would you
> want to create a new Configuration, when you can't do anything with it
> (it's read-only).
>
> Even more surprising is that for the single arg version, "createNew" is
> true. So getChild("foo") won't return null even if no child "foo"
> exists. I suppose this prevents inadvertent NPEs, but also prevents
> useful tests like:
>
> if (conf.getChild("foo") != null) {
> 	// ..
> }
>
> Is there a reason for returning an empty child Configuration, or is this
> a bug?

Its a feature so that we can support a pattern like

c = getChild("foo").getChild("bar").getChild("baz");

rather than 

Configuration foo = getChild("foo");
if( null != foo )
{
  Configuration bar = getChild("bar");
  if( null != bar )
  {
    c = getChild("baz");
  }
}


-- 
Cheers,

Pete

----------------------------------------
Whatever you do will be insignificant, 
but it is very important that you do it. 
                              --Gandhi
----------------------------------------

--
To unsubscribe, e-mail:   <mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>


Mime
View raw message