[jdom-interest] XMLOutputter & null pointer exception.

Jason Hunter jhunter at collab.net
Tue Aug 15 17:20:13 PDT 2000

"Quigley, James P" wrote:
> The larger issue is whether getText should return null for an empty 
> String.
> I looked at getTextTrim and it will
> return an empty String. I'd expect the two methods to return identical
> values for an empty string. My preference
> would be the empty string to avoid pesky null pointer exceptions.

In one way it's actually a bug in Element, because a setText("") creates
an empty String content node but then a getText() right after returns
null.  That caused XMLOutputter to get confused when it saw a single
String content node but got the null from getText().

I just did a CVS check-in so 'setText(""); getText()' returns "".  That
at least makes things work in the interim.

Now let's decide what we want long term.  What should getText() and
getMixedContent() return for all these?


Having all return null for getText() and empty lists for
getMixedContent() seems like the best choice after 15 seconds of
thinking.  That would mean setText("") would act like setText(null).


More information about the jdom-interest mailing list