[jdom-interest] [Vote] NoSuchChildException

Jason Hunter jhunter at collab.net
Thu Jul 13 00:56:45 PDT 2000

I was just talking with James Davidson and asked for his opinion on the
"null vs exception" issue.  He said, "No doubt, return null." 
Considering how much I trust his opinion, and how well his design
suggestions made in the early days of JDOM have played out, I'm now
convinced beyond a shadow of a doubt.  

Being that we had an overwhelming set of +1 votes for "null" including
the binding votes of Brett and myself (so glad we agree), I've now made
the change in the tree.  I changed getChild(), getAttribute(),
getRootElement(), and getProcessingInstruction() to return null if no
such item was found.  I also removed NoSuch* classes from the tree.  I'm
-1 on adding hasChild() because a null check is sufficient.  No reason
to bloat the API.

One of the great things about being pre-release is that we can make this
change without keeping around the old methods for backward
compatability.  One of the bad things is that because you're using
pre-release software, your programs are very very likely going to break
the next time you do a "cvs update".  Please bear that in mind.

If someone could modify the WarReader sample to be more robust with some
extra null checks, I'd appreciate it.  A patch to the list would be
great.  Also, if contrib authors could look over their code and check
for places where they're risking NPEs, that would be good too.

And remember, don't come cryin' to the list when your customer sees an
NPE and blames you, not their screwed up document.  You promised you'd
be careful out there.  ;-)


More information about the jdom-interest mailing list