Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4972882

two identity-constraints with the same {name} and {target namespace} are allowed

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b36
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      Name: erR10175 Date: 12/26/2003


       
      The test in JCK 1.5
        api/xml_schema/structures/IdConstrDefs/targetNS/targetNS00101m/targetNS00101m2.html#Negative

      fails because RI does not detect two identity-constraints defined with the same {name}
      and {target namespace}.

      The XML Schema Part 1: Structures (Section 3.11.1 The Identity-constraint Definition Schema
      Component) reads:

      "Identity-constraint definitions are identified by their {name} and {target namespace};
      Identity-constraint definition identities must be unique within an žXML Schemaž."

      So, the test schemas (see below) violate that constraint and an XML Schema validator must
      report an error.

      The bug is found in jdk1.5.0/beta/b32 and is not reproducible with previous builds.
       
      The bug seems to be in incorrect source file handling, because if the schema is in
      the current working directory and its basename used, the tests reports the error
      as expected. If the full path name of the schema file is used, the validator does not
      report any error. (see log below)

      To reproduce the bug put the following five files in your current working directory,
      compile and run the test.java as log shows.

      -------------------------- targetNS00101m2_stub.xml
      <?xml version='1.0'?>
      <sb:stub xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance&#39;
             xsi:schemaLocation='IdConstrDefs/targetNS targetNS00101m2_stub.xsd'
             xmlns:sb='IdConstrDefs/targetNS'>
          Stub document</sb:stub>
      --------------------------

      -------------------------- targetNS00101m2_stub.xsd
      <?xml version='1.0'?>
      <xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema&#39;
             targetNamespace='IdConstrDefs/targetNS'
             xmlns:sb='IdConstrDefs/targetNS'>
          <xsd:include schemaLocation='targetNS00101m2.xsd'/>
          <xsd:element name='stub' type='xsd:string'/>
      </xsd:schema>
      --------------------------

      -------------------------- targetNS00101m2.xsd
      <?xml version="1.0" encoding="UTF-8"?>
      <xsd:schema
        xmlns="IdConstrDefs/targetNS"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="IdConstrDefs/targetNS">

        <xsd:include schemaLocation="targetNS00101m2a.xsd"/>

        <xsd:element name="root">
            <xsd:complexType>
                <xsd:sequence maxOccurs="unbounded">
                    <xsd:element name="person">
                        <xsd:complexType>
                             <xsd:simpleContent>
                                  <xsd:extension base="xsd:string">
                                       <xsd:attribute name="parent" type="xsd:string" use="optional"/>
                                  </xsd:extension>
                             </xsd:simpleContent>
                        </xsd:complexType>
                    </xsd:element>
                </xsd:sequence>
            </xsd:complexType>
            <xsd:key name="KEY">
                <xsd:selector xpath="./person"/>
                <xsd:field xpath="."/>
            </xsd:key>
            <xsd:keyref name="KEYREF" refer="KEY">
                <xsd:selector xpath="./person"/>
                <xsd:field xpath="@parent"/>
            </xsd:keyref>
        </xsd:element>

      </xsd:schema>
      --------------------------

      -------------------------- targetNS00101m2a.xsd
      <?xml version="1.0" encoding="UTF-8"?>
      <xsd:schema
        xmlns="IdConstrDefs/targetNS"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="IdConstrDefs/targetNS">

        <xsd:element name="roota">
            <xsd:complexType>
                <xsd:sequence maxOccurs="unbounded">
                    <xsd:element name="person">
                        <xsd:complexType>
                             <xsd:simpleContent>
                                  <xsd:extension base="xsd:string">
                                       <xsd:attribute name="parent" type="xsd:string" use="optional"/>
                                  </xsd:extension>
                             </xsd:simpleContent>
                        </xsd:complexType>
                    </xsd:element>
                </xsd:sequence>
            </xsd:complexType>
            <xsd:key name="KEY">
                <xsd:selector xpath="./person"/>
                <xsd:field xpath="."/>
            </xsd:key>
            <xsd:keyref name="KEYREF" refer="KEY">
                <xsd:selector xpath="./person"/>
                <xsd:field xpath="@parent"/>
            </xsd:keyref>
        </xsd:element>

      </xsd:schema>
      --------------------------

      -------------------------- test.java
      import org.w3c.dom.Document;
      import javax.xml.XMLConstants;
      import java.io.File;
      import javax.xml.parsers.DocumentBuilderFactory;

      class test {
          static final String SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
          static final String SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";

          public static void main(String[] args) throws Exception {

              DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
              dbf.setNamespaceAware(true);
              dbf.setValidating(true);
              dbf.setAttribute(SCHEMA_LANGUAGE, XMLConstants.W3C_XML_SCHEMA_NS_URI);
              dbf.setAttribute(SCHEMA_SOURCE, args[0]);

              Document document = dbf.newDocumentBuilder().parse(args[1]);
              
              System.out.println("DONE");
          }
      }
      --------------------------

      -------------------------- log
      $ls
      targetNS00101m2.xsd targetNS00101m2_stub.xsd test.java
      targetNS00101m2_stub.xml targetNS00101m2a.xsd
      $javac test.java && java -cp . -showversion test targetNS00101m2_stub.xsd targetNS00101m2_stub.xml
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b32, mixed mode)

      Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
      set, which is probably not what is desired. Parser will use a default
      ErrorHandler to print the first 10 errors. Please call
      the 'setErrorHandler' method to fix this.
      Error: URI=targetNS00101m2a.xsd Line=21: sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of 'IdConstrDefs/targetNS,KEY'.
      Error: URI=targetNS00101m2a.xsd Line=25: sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of 'IdConstrDefs/targetNS,KEYREF'.
      DONE
      $javac test.java && java -cp . -showversion test `pwd`/targetNS00101m2_stub.xsd targetNS00101m2_stub.xml
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b32, mixed mode)

      DONE
      --------------------------

      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              kkawagucsunw Kohsuke Kawaguchi (Inactive)
              Reporter:
              reysunw Rey Rey (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: