JiBX
  1. JiBX
  2. JIBX-232

NPE in DomMapperBase using DOM Element with no namespace

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JiBX 1.1.6
    • Fix Version/s: JiBX 1.2.1
    • Component/s: core
    • Labels:
      None
    • Testcase included:
      yes
    • Patch Submitted:
      Yes
    • Number of attachments :
      2

      Description

      Marshalling a DOM element with org.jibx.extras.DomElementMapper caused:

      [junit] java.lang.NullPointerException
      [junit] at org.jibx.runtime.impl.UTF8StreamWriter.writeMarkup(UTF8StreamWriter.java:96)
      [junit] at org.jibx.runtime.impl.XMLWriterBase.startTagOpen(XMLWriterBase.java:196)
      [junit] at org.jibx.extras.DomMapperBase.marshalElement(DomMapperBase.java:236)
      [junit] at org.jibx.extras.DomElementMapper.marshal(DomElementMapper.java:129)

      The DOM document was created with no namespaces.

      The supplied test case fails with null element and attribute names rather than a NPE, but is the same problem. The test case uses the existing classes and bindings from the extras test package.

      A patch based on the JIBX1_1_6 branch follows:

          1. Eclipse Workspace Patch 1.0
            #P jibx_extras_116
            Index: org/jibx/extras/DomMapperBase.java
            ===================================================================
            RCS file: /cvsroot/jibx/core/build/extras/org/jibx/extras/DomMapperBase.java,v
            retrieving revision 1.3
            diff -u -r1.3 DomMapperBase.java
          • org/jibx/extras/DomMapperBase.java 21 May 2006 20:53:53 -0000 1.3
            +++ org/jibx/extras/DomMapperBase.java 28 Aug 2008 07:03:27 -0000
            @@ -233,7 +233,7 @@
            // check for namespace declarations required
            String[] uris = null;
            if (nss == null) { - m_xmlWriter.startTagOpen(nsi, element.getLocalName()); + m_xmlWriter.startTagOpen(nsi, element.getLocalName() != null ? element.getLocalName() : element.getNodeName()); }

            else {
            int base = getNextNamespaceIndex();
            if (defind >= 0) {
            @@ -273,8 +273,8 @@
            if (apref != null)

            { index = findNamespaceIndex(apref, attr.getNamespaceURI()); }
      • m_xmlWriter.addAttribute(index, attr.getLocalName(),
      • attr.getValue());
        + m_xmlWriter.addAttribute(index, attr.getLocalName() != null ? attr.getLocalName() : attr.getNodeName(),
        + attr.getValue());
        }
        }

      @@ -284,7 +284,7 @@
      if (size > 0)

      { m_xmlWriter.closeStartTag(); marshalContent(element.getChildNodes()); - m_xmlWriter.endTag(nsi, element.getLocalName()); + m_xmlWriter.endTag(nsi, element.getLocalName() != null ? element.getLocalName() : element.getNodeName()); }

      else

      { m_xmlWriter.closeEmptyTag(); }
      1. DomNoNSTest.java
        2 kB
        Nigel Charman
      2. jibx-232-patch.txt
        2 kB
        Nigel Charman

        Activity

        Hide
        Nigel Charman added a comment -

        Patch attached

        Show
        Nigel Charman added a comment - Patch attached
        Hide
        Dennis Sosnoski added a comment -

        Implemented this is a slightly different manner for 1.2.1, but found the test code too difficult to use. Give it a try if you can, and either verify the fix or add more details.

        Show
        Dennis Sosnoski added a comment - Implemented this is a slightly different manner for 1.2.1, but found the test code too difficult to use. Give it a try if you can, and either verify the fix or add more details.
        Hide
        Nigel Charman added a comment -

        Just tried with 1.2.1 and it's working OK. thanks.

        Show
        Nigel Charman added a comment - Just tried with 1.2.1 and it's working OK. thanks.

          People

          • Assignee:
            Dennis Sosnoski
            Reporter:
            Nigel Charman
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: