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

newDocumentBuilder(): no PCE when Schema and the 'schemaLanguage' attr set

    XMLWordPrintable

    Details

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

      Description

      Name: inR10064 Date: 12/11/2003



      The method
           javax.xml.parsers.DocumentBuilderFactory.newDocumentBuilder()

      does not throw ParserConfigurationException exception when a Schema object
      and the
           http://java.sun.com/xml/jaxp/properties/schemaSource

      property and/or the
           http://java.sun.com/xml/jaxp/properties/schemaLanguage

      property are set for this factory (please see log and source below).
      The spec for the method
          DocumentBuilderFactory.setSchema(Schema)

      requires that the exception is thrown in such configuration.

      The bug affects new tests in JCK 1.5 (not yet integrated):
        api/javax_xml/parsers/DocumentBuilderFactory/index.html#SetSchema[SetSchema401]
        api/javax_xml/parsers/DocumentBuilderFactory/index.html#SetSchema[SetSchema402]

      The bug found in the JDK 1.5.0-beta-b30.

      --------------------------------------------------------------------------
      package tests;

      import java.io.StringReader;
      import javax.xml.XMLConstants;
      import javax.xml.parsers.DocumentBuilder;
      import javax.xml.parsers.DocumentBuilderFactory;
      import javax.xml.parsers.ParserConfigurationException;
      import javax.xml.transform.stream.StreamSource;
      import javax.xml.validation.Schema;
      import javax.xml.validation.SchemaFactory;
      import org.xml.sax.InputSource;

      public class SchemaAttr {

          String schemaSource =
                            "<?xml version='1.0'?>\n"
                            + "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema&#39;>\n"
                            + " <xsd:element name='test101'>\n"
                            + " <xsd:complexType>\n"
                            + " <xsd:attribute name='attr'/>\n"
                            + " <xsd:attribute name='attr2' default='DEF'/>\n"
                            + " </xsd:complexType>\n"
                            + " </xsd:element>\n"
                            + "</xsd:schema>\n";

          Schema createSchema() {
              SchemaFactory schFactory = SchemaFactory.newInstance(
      XMLConstants.W3C_XML_SCHEMA_NS_URI);
      try {
      Schema sch = schFactory.newSchema(
      new StreamSource(
      new StringReader(schemaSource)
      ));
      return sch;
      } catch (Exception se) {
      throw new IllegalStateException("No Schema : " + se);
      }
          }

          void setAttr(boolean setSrc) {
              DocumentBuilderFactory docBFactory = DocumentBuilderFactory.newInstance();
              Schema sch = createSchema();
              docBFactory.setSchema(sch);
              docBFactory.setNamespaceAware(true);
              docBFactory.setValidating(true);

              final String aSchemaLanguage =
      "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
      final String aSchemaSource = "http://java.sun.com/xml/jaxp/properties/schemaSource";

      docBFactory.setAttribute(aSchemaLanguage, "http://www.w3.org/2001/XMLSchema");
      System.out.println("---- Set schemaLanguage: "+
      docBFactory.getAttribute(aSchemaLanguage));
      if (setSrc) {
                 docBFactory.setAttribute(aSchemaSource,
                                          new InputSource(new StringReader(schemaSource)));
      System.out.println("---- Set schemaSource: "+
      docBFactory.getAttribute(aSchemaSource));
      }

              DocumentBuilder docBuilder;
              try {
                  docBuilder = docBFactory.newDocumentBuilder();
              } catch (ParserConfigurationException pce) {
                  pce.printStackTrace();
                  return;
              }
      System.out.println("-- No errors: "+ docBuilder);
          }

          public static void main(String argv[]) {
      SchemaAttr test = new SchemaAttr();
      test.setAttr(false);
      test.setAttr(true);
          }

      }

      --------------------------------------------------------------------------
      % java -showversion tests.SchemaAttr
      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)

      ---- Set schemaLanguage: http://www.w3.org/2001/XMLSchema
      -- No errors: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl@1960f05
      ---- Set schemaLanguage: http://www.w3.org/2001/XMLSchema
      ---- Set schemaSource: org.xml.sax.InputSource@6f7ce9
      -- No errors: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl@171bbc9

      --------------------------------------------------------------------------

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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: