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

TypeInfo.isDerivedFrom(...) does not regard the derivation method parameter

XMLWordPrintable

    • 1.3
    • generic
    • generic

        Name: erR10175 Date: 12/10/2003


         
            If a TypeInfo instance refers to a complex type derived from another complex type
        by extension the method TypeInfo.isDerivedFrom(...) returns true with no regard to
        its derivation parameter.

        The documentation of the method reads:

        "Returns: true if the specified type is an ancestor according to the derivation parameter,
        false otherwise."

        So, the test (see below) expects to get true for DERIVATION_EXTENSION and 0, and false for
        DERIVATION_RESTRICTION, DERIVATION_UNION and DERIVATION_LIST.

        This bug affects new test in JCK 1.5 (not integrated yet)
           api/org_w3c/dom/TypeInfo/index.html#TypeInfo[IsDerivedFrom002]

        The bug is found in jdk1.5.0/beta/b30.

        To reproduce the bug place test.java, test.xsd and test.xml to your current
        directory, then compile and run test.java as shown in the log below:
        ------------------------------------------ test.java
        import org.w3c.dom.Document;
        import org.w3c.dom.TypeInfo;
        import javax.xml.XMLConstants;
        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, "test.xsd");

                Document document = dbf.newDocumentBuilder().parse("test.xml");

                TypeInfo type = document.getDocumentElement().getSchemaTypeInfo();

                if (type.isDerivedFrom("testNS", "Test", TypeInfo.DERIVATION_UNION)) {
                    System.out.println("DERIVATION_UNION: true"); // unexpected
                }
                if (type.isDerivedFrom("testNS", "Test", TypeInfo.DERIVATION_LIST)) {
                    System.out.println("DERIVATION_LIST: true"); // unexpected
                }
                if (type.isDerivedFrom("testNS", "Test", TypeInfo.DERIVATION_RESTRICTION)) {
                    System.out.println("DERIVATION_RESTRICTION: true"); // unexpected
                }
                if (!type.isDerivedFrom("testNS", "Test", TypeInfo.DERIVATION_EXTENSION)) {
                    System.out.println("DERIVATION_EXTENSION: false"); // unexpected
                }
                if (!type.isDerivedFrom("testNS", "Test", 0)) {
                    System.out.println("DERIVATION_ANY: false"); // unexpected
                }
            }
        }
        ----------------------------------------------------

        ------------------------------------------- test.xsd
        <?xml version="1.0"?>
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                    xmlns:testNS="testNS"
                    targetNamespace="testNS" elementFormDefault="qualified">
            
            <xsd:element name="test6">
                <xsd:complexType>
                    <xsd:complexContent>
                        <xsd:extension base="testNS:Test">
                            <xsd:attribute name="attr" type="xsd:string"/>
                        </xsd:extension>
                    </xsd:complexContent>
                </xsd:complexType>
            </xsd:element>

            <xsd:complexType name="Test">
                <xsd:sequence>
                    <xsd:element name="description" minOccurs="0"/>
                    <xsd:element name="code"/>
                </xsd:sequence>
            </xsd:complexType>

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

        ------------------------------------------- test.xml
        <?xml version='1.0'?>
        <test6 xmlns="testNS" attr="x"><code/></test6>
        ----------------------------------------------------

        ------------------------------------------------ log
        $javac test.java && java -cp . -showversion test
        java version "1.5.0-beta"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b30)
        Java HotSpot(TM) Client VM (build 1.5.0-beta-b30, mixed mode)

        DERIVATION_UNION: true
        DERIVATION_LIST: true
        DERIVATION_RESTRICTION: true
        ----------------------------------------------------

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

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

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: