logo       

Re: question(bug) about setNodeValue: msg#00119

java.enhydra.xmlc

Subject: Re: question(bug) about setNodeValue

At 02:25 PM 9/18/2003 +0800, you wrote:
hi,

I find that when call setNodeValue with "null", xmlc will report errors like below:

java.lang.NullPointerException
at org.enhydra.xml.io.BaseDOMFormatter.writeText(BaseDOMFormatter.java:535)

[snip]

The reason why the null pointer is happening is that the writeText() method doesn't do a null check on the text string being passed in.....

protected final void writeText(String text) throws IOException {
int len = text.length();
char ch;

// FIXME: here we make a nasty assumption about all characters
// less than fMaxCharacterValue && MAX_ENTITY_QUICK_CHECK_CHAR
// are valid. This is probably ok. The fMaxCharacterValue check
// is needed for 7-bit encodings.
for (int idx = 0; idx < len; idx++) {
ch = text.charAt(idx);
if ((ch <= fMaxCharacterValue)
&& (ch <= MAX_ENTITY_QUICK_CHECK_CHAR)
&& (!fEntityQuickCheck[ch])) {
fOut.write(ch); // Fast path.
} else {
writeCharacter(ch);
}
}
}

My codes like this:
....
HTMLElement ipAddr = (HTMLElement) page.getElementById(LIST_IPADDR_TAG);
ipAddr.getFirstChild().setNodeValue(current.getIpAddr()); // <-- here, getIpAddr() may return null
....
context.writeDOM(req, resp, page);

Accroding to api doc, setNodeVaule can accept null parameter:

The value of this node, depending on its type; see the table above. When it
is defined to be null, setting it has no effect.

Hmm...... So, does this mean that the initial value shouldn't have been modified? In the DOM, what is the initial value of a Text node? Can it be null or would that, by definition, mean that there wouldn't be a text node in the first place? It it couldn't be null as an initial value and passing null to setNodeValue() is supposed to leave the initial value alone rather than set it to null, then how could a Text node value of null be passed to BaseDOMFormatter#writeText()? We could certainly do the null check in the writeText() method, but should we have to do that? Would that even be the correct thing to do? Seems like the bug here might lay somewhere in the Xerces1 DOM implemementation. Thoughts anyone?


So, what happened with setNodeValue?

Your guess is as good as mine. I'll look into it a bit and hopefully others will to.

Jake

Thanks!

linuxman

_______________________________________________
XMLC mailing list
XMLC@xxxxxxxxxxx
http://www.enhydra.org/mailman/listinfo.cgi/xmlc


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise