[jdom-interest] Element.getText() - Bug report
Guy Nirpaz
guyn at tantian.com
Mon Oct 2 09:49:59 PDT 2000
Hi,
Element getText() has the following bug. (from this morning CVS)
public String getText() {
// If we hold only a String, return it directly
if ((content != null) && (content.size() == 1)) {
if (content.get(0) == null) {
return null;
} else if (content.get(0) instanceof String) {
return (String) content.get(0);
}
}
StringBuffer textContent = new StringBuffer();
boolean hasText = false;
+++++
+++++ content here can be null and the following results in a
NullPointerException
+++++ A fix should test if content isn't null
Iterator i = content.iterator();
+++++
+++++
+++++
while (i.hasNext()) {
Object obj = i.next();
if (obj instanceof String) {
textContent.append((String)obj);
hasText = true;
} else if (obj instanceof CDATA) {
textContent.append(((CDATA)obj).getText());
hasText = true;
}
}
if (!hasText) {
return null;
} else {
return textContent.toString();
}
}
Guy Nirpaz
Java Architect
Tantian Corp.
guyn at tantian.com
More information about the jdom-interest
mailing list