#182 NullPtrException using DOMSource

v7.8
closed
Michael Kay
5
2012-10-08
2004-01-26
Michael Kay
No

A NullPointerException may occur in the NamePool when
taking input from a DOM Source. I haven't been able to
determine the exact conditions, a necessary but not
sufficient condition is that the source document has a
default namespace declaration.

The fix is to change the code at line 302 of
net.sf.saxon.dom.DOMWrapper to:

            if (node.getNamespaceURI() != null) {
                String prefix = node.getPrefix();
                if (prefix == null) {
                    prefix = "";
                }
                namecode =

docWrapper.namePool.allocate(prefix,

node.getNamespaceURI(),

node.getLocalName());
return namecode;
}

Michael Kay

Discussion

  • Milan Trninic
    Milan Trninic
    2004-03-07

    Logged In: YES
    user_id=992516

    I haven't analyzed this enough to be sure, but it seems to me
    that the following is sufficient:

    1. The element is not prefixed
    2. There is no prefix bound to the default namespace
    3. Default namespace is declared

    Like this:
    <SomeElement xmlns="http://www.site.com">
    </SomeElement>

    The following doesn't cause the exception:

    <abc:SomeElement xmlns="http://www.site.com" xmlns:abc="http://www.site.com">
    </abc:SomeElement>

    Milan