On Sat, Nov 10, 2001 at 09:23:25PM +1100, Peter Donald wrote:
> On Sat, 10 Nov 2001 21:22, Jeff Turner wrote:
[..]
> > 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");

If /foo/bar exists, that will work under either system. If /foo or /foo/bar
doesn't exist, isn't it a logical error for the program to assume it
does? What can be done with an empty 'c' object?

And to gain this "feature", one gives up the logical way to check for a
subelement's presence (a null check). Though I guess it can still be
done with:

if (conf.getChid("foo", false) == null) {
        // ..
}

Anyway, if it's being used in the way you say, the issue probably isn't
worth breaking everyone's code over.

--Jeff

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

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to