[jdom-interest] BUG in Document

Frank Morton fmorton at base2inc.com
Fri Feb 9 11:01:39 PST 2001


> Frank Morton wrote:
> 
> > I'm a newbie (today), but really like what I see so far and will
> > be happy to contribute significantly. I'm using code freshly
> > checked out of CVS.
> >
> > If you do:
> >
> > Document doc = new Document();
> > doc.setRootElement(new Element("something"));
> >
> > You get a NullPointerException because "content" is
> > not initialized when using the no arg constructor.
> 
> Why not use the following:
> 
> Document doc = new Document( new Element("something") );
> 
> Won't this give you the intended result?
> 
> > So, I added the following to the first line of setRootElement(element):
> >
> > if(content == null) content = new LinkedList();
> >
> > Since I'm new to the code, don't know if this is the best way to
> > do this. So, what is the process of bug fixing?
> >
> > Just to head this off, I need to be able to do it this way because
> > I'm writing a class that extends Document, so it needs to construct
> > the Document before it has a chance to create what is going to
> > be the root element.

What I am doing is creating a class that (among other things) 
sets the root element as part of the constructor like:

public class Key extends Document {
     public Key() {
          super();
          setRootElement(new Element("key"));
     }
}

I wish I could do in the constructor:

     super(new Element("key"));

But, you can't do that. Anyway, we're getting away from the point.

You should be able to set the root element after using the default
constructor when you are extending the class and I've provided
a bug fix, but am new enough that I don't know how to get the
bug fix integrated into the base code.

Frank






More information about the jdom-interest mailing list