[jdom-interest] getText() and getAttributeValue()

Jason Hunter servlets at mindspring.com
Thu Feb 14 10:29:53 PST 2002

> Why would any method of any class in any API that returns String want to
> return null instead of empty string?

I think Phil said it best.  At the relatively low-level of JDOM, more
information is better.

As a second argument, we need

Attribute Element.getAttribute(String)

to return null if the attribute doesn't exist.  We're not going to
return a NO_ATTRIBUTE constant or anything fancy.  So for consistency,
we should have getAttributeValue(String) return null also.  The "value"
method is a convenience on top of the former.

> If one were REALLY concerned with making sure the
> programmer was aware of his error, getAttributeValue() would have been
> written to throw a java.util.NoSuchElementException or such a long time ago.

How ironic!  It was!  We changed to null after a vote.


More information about the jdom-interest mailing list