[jdom-interest] XMLOutputter & null pointer exception.

Bolt, Dave boltd at atsc.army.mil
Wed Aug 16 06:39:31 PDT 2000

The real question is that of fidelity. If you view XML (and JDOM by
extension) as a "pipe",
the data I put in should be the data that I get out.

Consider the situation of someone building an XML bridge between two
databases. Imagine a
table in each database called Employee. Let's assume that the field holding
the middle
name is an empty string, but not NULL. If I serialize the data from DB #1
into XML via
JDOM and then extract the data for use in DB #2 JDOM will have turned my
empty string into
a Java null. So use of XML and JDOM has changed my data.

The best approach would maintain the fidelity of the data, but it is going
to be difficult
to decide the appropriate way to handle the data. Clearly an empty tag
should return NULL
when someone tries to get the tag's content. The problem is how do we handle
an empty string
so that it does not get translated into a NULL.

Dave Bolt
Bolt's Law of Bandwidth - There is always plenty of network bandwidth, just
none for you.

-----Original Message-----
From: Jason Hunter [mailto:jhunter at collab.net]
Sent: Tuesday, August 15, 2000 8:20 PM
To: Quigley, James P
Cc: jdom-interest at jdom.org
Subject: Re: [jdom-interest] XMLOutputter & null pointer exception.

"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).

To control your jdom-interest membership:

More information about the jdom-interest mailing list