NullPointerException when namespace is null

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

NullPointerException when namespace is null

Eleanor Joslin
Hi,

net.sf.saxon.dom.ElementOverNodeInfo in Saxon-B 8.6.1 throws a
NullPointerException when either getAttributeNS() or
getAttributeNodeNS() is called with a null namespace.

java.lang.NullPointerException
      at
net.sf.saxon.om.NamespaceConstant.isReserved(NamespaceConstant.java:210)
      at net.sf.saxon.om.NamePool.allocate(NamePool.java:451)
      at net.sf.saxon.om.Navigator.getAttributeValue(Navigator.java:44)
      at
net.sf.saxon.dom.ElementOverNodeInfo.getAttributeNS(ElementOverNodeInfo.java:147)

or:

java.lang.NullPointerException
      at net.sf.saxon.om.NamePool.getFingerprint(NamePool.java:753)
      at
net.sf.saxon.dom.ElementOverNodeInfo.getAttributeNodeNS(ElementOverNodeInfo.java:213)

Looking at the code, this appears to be because it expects the anonymous
namespace to be represented by "".  However, this is incompatible with
the DOM 3 Core spec, which expects null.

http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-745549614

"getAttributeNS introduced in DOM Level 2
     Retrieves an attribute value by local name and namespace URI.
     Per [XML Namespaces], applications must use the value null as the
namespaceURI parameter for methods if they wish to have no namespace."

A JUnit test case and sample XML file are attached.

Thank you,

        Eleanor Joslin

--
Eleanor Joslin, Software Development   DecisionSoft Ltd.
Telephone: +44-1865-203192             http://www.decisionsoft.com

import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

import junit.framework.TestCase;
import net.sf.saxon.dom.DocumentBuilderFactoryImpl;

public class SaxonBug extends TestCase {

  private Element _element;

  public void setUp() throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory documentBuilderFactory = new DocumentBuilderFactoryImpl();
    documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();

    InputStream xmlStream = getClass().getResourceAsStream("test.xml");
    Document document = documentBuilder.parse(xmlStream);
    _element = document.getDocumentElement();
  }

  /**
   * Tests the getAttributeNS() method with a null namespace.
   */
  public void testGetAttributeNS() {
    assertEquals("something", _element.getAttributeNS(null, "attribute"));
  }

  /**
   * Tests the getAttributeNodeNS() method with a null namespace.
   */
  public void testGetAttributeNodeNS() {
    assertNotNull(_element.getAttributeNodeNS(null, "attribute"));
  }

}

<my:test xmlns:my="http://www.example.com/attribute/in/default/namespace" attribute="something"/>
Reply | Threaded
Open this post in threaded view
|

RE: NullPointerException when namespace is null

Michael Kay
Thanks for reporting this. I've fixed the source code (there are a couple of
other instances beyond those you mentioned) and have registered the bug at

https://sourceforge.net/tracker/?func=add&group_id=29872&atid=397617

I haven't actually supplied the source changes since they are pretty obvious
(to anyone capable of applying them!)

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> Eleanor Joslin
> Sent: 03 January 2006 10:32
> To: [hidden email]
> Subject: [saxon] NullPointerException when namespace is null
>
> Hi,
>
> net.sf.saxon.dom.ElementOverNodeInfo in Saxon-B 8.6.1 throws a
> NullPointerException when either getAttributeNS() or
> getAttributeNodeNS() is called with a null namespace.
>
> java.lang.NullPointerException
>       at
> net.sf.saxon.om.NamespaceConstant.isReserved(NamespaceConstant
> .java:210)
>       at net.sf.saxon.om.NamePool.allocate(NamePool.java:451)
>       at
> net.sf.saxon.om.Navigator.getAttributeValue(Navigator.java:44)
>       at
> net.sf.saxon.dom.ElementOverNodeInfo.getAttributeNS(ElementOve
> rNodeInfo.java:147)
>
> or:
>
> java.lang.NullPointerException
>       at net.sf.saxon.om.NamePool.getFingerprint(NamePool.java:753)
>       at
> net.sf.saxon.dom.ElementOverNodeInfo.getAttributeNodeNS(Elemen
> tOverNodeInfo.java:213)
>
> Looking at the code, this appears to be because it expects
> the anonymous
> namespace to be represented by "".  However, this is
> incompatible with
> the DOM 3 Core spec, which expects null.
>
> http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.h
> tml#ID-745549614
>
> "getAttributeNS introduced in DOM Level 2
>      Retrieves an attribute value by local name and namespace URI.
>      Per [XML Namespaces], applications must use the value
> null as the
> namespaceURI parameter for methods if they wish to have no namespace."
>
> A JUnit test case and sample XML file are attached.
>
> Thank you,
>
> Eleanor Joslin
>
> --
> Eleanor Joslin, Software Development   DecisionSoft Ltd.
> Telephone: +44-1865-203192             http://www.decisionsoft.com
>




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help