sjsxp
  1. sjsxp
  2. SJSXP-13

XMLStreamWriter should ignore duplicate namespaces written on the same element

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Cannot Reproduce
    • Affects Version/s: current
    • Fix Version/s: milestone 1
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      13

      Description

      In the following program, XMLStreamWriter.writeNamespace() is called with the
      same namespace prefix and namespaceURI twice.

      ----------
      import javax.xml.stream.*;
      public class DuplicateNSBug {
      public static void main(String args[])

      { DuplicateNSBug bug = new DuplicateNSBug(); bug.reproduce(); }

      private void reproduce() {
      try

      { XMLStreamWriter w = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out); w.writeStartDocument(); w.writeStartElement("ns1","foo","http://example.com/"); w.writeNamespace("ns1","http://example.com/"); w.writeNamespace("ns1","http://example.com/"); w.writeEndElement(); w.writeEndDocument(); w.close(); }

      catch (XMLStreamException e)

      { e.printStackTrace(); }

      }
      }
      ----------------
      The output produced by the program is
      <?xml version="1.0" ?><ns1:foo xmlns:ns1="http://example.com/" xmlns:ns1="http:/
      /example.com/"></ns1:foo>

      Although writing the same namespace is twice on the same element is not a common
      case, JAX-WS faces this situation in many places. JAX-WS has to colloborate
      with many other components when writing documents and JAX-WS has no idea if a
      namespace is already written. In attempt to write the namespace, its producing
      incorrect documents with duplicate namespaces as you see in the output shown
      above. If Stax can identify such duplicate namespaces and ignore if the same
      namesapce with same prefix is already declared, it would help JAX-WS get past
      many issues while creating SOAP messages.

        Activity

        Hide
        Santiago Pericas-Geertsen added a comment -

        Assigning this one to Jeff for evaluation.

        Show
        Santiago Pericas-Geertsen added a comment - Assigning this one to Jeff for evaluation.
        Hide
        jeffsuttor added a comment -

        note that a CR is being worked that is related to this issue:

        http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6475032

        Show
        jeffsuttor added a comment - note that a CR is being worked that is related to this issue: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6475032
        Hide
        jeffsuttor added a comment -

        a unit test was created:

        https://sjsxp.dev.java.net/source/browse/sjsxp/zephyr/tests/XMLOutputFactory/DuplicateNSDeclarationTest.java

        note the use of IS_REPAIRING_NAMESPACES:

        // have XMLOutputFactory repair Namespaces
        XMLOutputFactory ofac = XMLOutputFactory.newInstance();
        ofac.setProperty(
        XMLOutputFactory.IS_REPAIRING_NAMESPACES,
        new Boolean(true));

        unit test passes when property is set.

        Show
        jeffsuttor added a comment - a unit test was created: https://sjsxp.dev.java.net/source/browse/sjsxp/zephyr/tests/XMLOutputFactory/DuplicateNSDeclarationTest.java note the use of IS_REPAIRING_NAMESPACES: // have XMLOutputFactory repair Namespaces XMLOutputFactory ofac = XMLOutputFactory.newInstance(); ofac.setProperty( XMLOutputFactory.IS_REPAIRING_NAMESPACES, new Boolean(true)); unit test passes when property is set.

          People

          • Assignee:
            jeffsuttor
            Reporter:
            ramapulavarthi
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: