Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#243 Missing overriding method in DOMAttrImpl

open
nobody
None
5
2012-10-08
2011-02-03
David Tonhofer
No

Problem:

The class DOMAttrImpl extends DOMNodeImpl

with the special feature that the "adaptee" given to DOMNodeImpl at construction time is null and DOMAttrImpl uses its own "avAdaptee" instead.

As most of the methods of "DOMNodeImpl" dereference "adaptee", methods need to be overriden in "DOMAttrImpl" (actually, this indicates a design problem whereby using a common interface instead of a subclass relationship would be a better choice, but I digress)

Now, DOMNodeImpl has a non-overriden method:

/**
 * @see org.w3c.dom.Node#hasAttributes
 */
public boolean hasAttributes()
{
    // contributed by dlp@users.sourceforge.net
    return this.adaptee.attributes != null;
}

So one has to add the following in DOMAttrImpl, otherwise a NullPointerException will occur as soon as one dumps a DOM Tree:

/**
 * @see org.w3c.dom.Node#hasAttributes
 */
@Override
public boolean hasAttributes()
{
    // Does an attribute implementation have attributes? Guess not 
    return false;
}

See attached test case. It crashes if the above is not applied.

Discussion

  • David Tonhofer
    David Tonhofer
    2011-02-03

    Test Case (most is support code of no interest though)

     
    Attachments