jaxb
  1. jaxb
  2. JAXB-452

Embedded DOM Elements may lose locally defined namespace prefixes

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.5
    • Fix Version/s: 2.2.7
    • Component/s: runtime
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

      Description

      JAXB's marshaller allows embedding generic DOM Elements in the following
      locations, as far as I am aware of.

      • A value of a JAXBElement<>.
      • An Object-typed field/property annotated with @XmlElement.

      Such embedded elements may have attributes of which values are qualified names.
      The most significant those attributes might be xsi:type attribute. Although the
      prefixes used in those qualified names are defined like normal XML namespaces
      using xmlns:<prefix> syntax, XML processors cannot change them because they do
      not know which attribute has a qualified name as its value.

      However, while writing the embedded element, JAXB RI's marshaller omits a local
      namespace prefix definition if it is already defined outside the element where
      the embedded element's contents are going to be written into. This causes a
      problem when local attributes of which values are qualified names using the
      prefix. Since the prefix is no longer defined in the resulted XML document,
      readers of the document cannot determine the namespace URI associated with the
      qualified name.

      I believe that the marshaller should always emit a local prefix definition even
      if its namespace URI is already assigned to another prefix. In fact, the
      marshaller currently emits a prefix definition even if it is defined as the
      default namespace. Please look into the attached test case and find
      testSuccess2() do this.

      P.S. Although the attached case might seem a bit synthetic, I actually stumbled
      upon the issue while writing a piece of code for a real world project.

        Activity

        Hide
        kamishim added a comment -

        Created an attachment (id=223)
        a JUnit test case to clarify the issue

        Show
        kamishim added a comment - Created an attachment (id=223) a JUnit test case to clarify the issue
        Hide
        Pavel Bucek added a comment -

        fixed in 2.1.10

        Show
        Pavel Bucek added a comment - fixed in 2.1.10
        Hide
        Pavel Bucek added a comment -

        fix was reverted due to regression in JAX-WS

        Show
        Pavel Bucek added a comment - fix was reverted due to regression in JAX-WS
        Hide
        Iaroslav Savytskyi added a comment -

        I've ran test with JAXB 2.2.7 version and all 3 tests passed.

        Show
        Iaroslav Savytskyi added a comment - I've ran test with JAXB 2.2.7 version and all 3 tests passed.

          People

          • Assignee:
            Iaroslav Savytskyi
            Reporter:
            kamishim
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: