[jdom-interest] Element.getText() null vs. ""

Jeff Turner jeff at socialchange.net.au
Tue Apr 17 21:40:18 PDT 2001


On Tue, Apr 17, 2001 at 03:07:38PM -0700, Jason Hunter wrote:
> D Gross wrote:
> > 
> > Element.getText() returns an empty String if the content is null.  The
> > javadoc says this, but also says it will return null (in the @return
> > doc).  I think it is more appropriate for it to return null than "",
> > since "" implies the Element has content.
> 
> If you look at the latest CVS code (which everyone should PLEASE do
> before you report bugs) you'll note the Javadocs are consistent that get
> Text() returns "" if there's no text content.
> 
> This is appropriate because: <foo></foo> can easily be seen as having ""
> as text content.

And it can also easily be seen as having no body, therefore no text nodes,
therefore getText() == null.

At least that was the point of view of a JBoss developer I once talked to. The
context was different (Tomcat's do*Body() methods in JSP taglib handlers [1]), but
the issue is the same. Do you have a killing argument in favour of your (and
my) POV?

--Jeff

[1] http://nagoya.apache.org/bugzilla/show_bug.cgi?id=366


> -jh-



More information about the jdom-interest mailing list