[jdom-interest] Element.getText() - Bug report

Brett McLaughlin brett.mclaughlin at lutris.com
Mon Oct 2 10:06:34 PDT 2000


Guy Nirpaz wrote:
> 
> 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 - I rewrote the beginning of that method to be a little better, and
should have fixed your problem. Can you get the latest from CVS and try
it?

Thanks,
Brett

> 
> Guy Nirpaz
> Java Architect
> 
> Tantian Corp.
> guyn at tantian.com
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com

-- 
Brett McLaughlin, Enhydra Strategist
Lutris Technologies, Inc. 
1200 Pacific Avenue, Suite 300 
Santa Cruz, CA 95060 USA 
http://www.lutris.com
http://www.enhydra.org



More information about the jdom-interest mailing list