Uploaded image for project: 'Xerces2-J'
  1. Xerces2-J
  2. XERCESJ-1165

Problem resolving namespace prefix for QName, suspected bug in NamespaceSupport

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Incomplete
    • 2.8.0
    • None
    • XML Schema API
    • None
    • Windows XP SP2, JRE 1.5.0_06

    Description

      I think I found a bug in the NamespaceSupport class which is part of Xerces2-J. I'm working on a project which involves elements which have a QName as type. Let me just write some XML to clarify:

      <xbrli:xbrl xmlns:iso4217="http://www.xbrl.org/2003/iso4217">
      <xbrli:unit id="EUR">
      <xbrli:measure>iso4217:EUR</xbrli:measure>
      </xbrli:unit>
      </xbrli:xbrl>

      I'm trying to validate this using JAXP with the Xerces implementation. The schema for the measure element is as follows:

      <xsd:element name="measure" type="QName"/>

      Now, when the validation is run an exception is thrown which reads as follows:

      UndeclaredPrefix: Cannot resolve 'iso4217:EUR' as a QName: the prefix 'iso4217' is not declared.

      This is quite strange because the namespace prefix is clearly declared at the top level element. So I decided to have a debug through the code and found that the problem is in the NamespaceSupport class. At the bottom of the getActualValue method of the QNameDV class the method getURI is called on the ValidationContext that was passed to it. This eventually calls the getURI(String) method on the NamespaceSupport class. The code here reads as follows:

      1. // find prefix in current context
      2. for (int i = fNamespaceSize; i > 0; i -= 2) {
      3. if (fNamespace[i - 2] == prefix)

      { 4. return fNamespace[i - 1]; 5. }

      6. }
      7.
      8. // prefix not found
      9. return null;

      The fNamespace instance variable is a String array and the prefix argument is a String as well. This leads me to conclude that line 3 of the above code should have been written as follows:

      if (fNamespace[i -2].equals(prefix)) {

      String comparison in Java is done using the equals method rather than the equals operator as far as I know.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jmezach Jonathan Mezach
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: