[jdom-interest] Bug in Document(List) -> setMixedContent()

Jason Hunter jhunter at collab.net
Mon Jun 25 21:04:08 PDT 2001


> Here is a patch to Document that fixes a problem similar to one reported
> earlier today with Element.
> This really can't work unless the document already existed.  oldRoot is null
> on a new document which causes NPE's so this patch allows you to create a
> new document from a starter List.

Integrated.  Please verify.

>         finally {
>             if (ex != null) {
>                 // Restore the original state and parentage and throw
>                 if (oldRoot != null) { //*******************
>                         content = oldContent;
>                         oldRoot.setDocument(this);
>                         // Unmodify all modified elements.  DO NOT change

I did a more limited if clause.  Yours appears to wrap all logic, but
shouldn't it just wrap the oldRoot.setDocument()?

> I also patched Document(List, DocType)to throw an NPE if the list is null
> which would result in an invalid state. I suppose the NPE is arguable but
> this is better than returning a useless document.
> 
>     public Document(List content, DocType docType) {
>             if (content == null)
>                     throw new NullPointerException();
> 
>         setMixedContent(content);
>         setDocType(docType);
>     }

Whether or not you can have a truly empty doc is not really decided.

> My updated test suite still has a couple of other places where Document
> doesn't handle nulls but these are documented as TODO's and can wait.

Good 'nuff.

-jh-



More information about the jdom-interest mailing list