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

validation.SchemaFactory: block="list" is allowed for element declarations

XMLWordPrintable

    • b96
    • generic
    • generic

      Name: erR10175 Date: 02/03/2004


       
        The method

      public Schema newSchema(File schema)

      in the class javax.xml.validation.SchemaFactory allows values "list" and "union"
      for attribute 'block' of element declaration.

      That is prohibited by XML Schema Part 1: Structures, Section 3.3.2 XML Representation
      of Element Declaration Schema Components:

      "<element
        abstract = boolean : false
        block = (#all | List of (extension | restriction | substitution))
        ..."

      So the RI should report an error, but it does not.

      The bug affects the following new JCK1.5 beta2 tests adopted from W3C XSTC-20020116 testsuite:
          api/xml_schema/msxsdtest/element/elemT009.html#elemT009
          api/xml_schema/msxsdtest/element/elemT010.html#elemT010

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

      To reproduce the bug compile and run the following code as shown in the log below.
      ------------------------------------------- test.xsd
      <?xml version="1.0"?>
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
              <xsd:element name="fooTest1" type="xsd:int" block="list"/>
              <xsd:element name="fooTest2" type="xsd:int" block="union"/>
      </xsd:schema>
      ----------------------------------------------------

      ------------------------------------------ test.java
      import java.io.File;
      import org.xml.sax.SAXException;
      import org.xml.sax.SAXParseException;
      import org.xml.sax.helpers.DefaultHandler;
      import javax.xml.validation.SchemaFactory;

      public class test {

          protected static class ErrorHandler extends DefaultHandler {
              public int errorCounter = 0;

              public void error(SAXParseException e) throws SAXException {
                  System.out.println(e);
                  errorCounter++;
              }

              public void fatalError(SAXParseException e) throws SAXException {
                  System.out.println(e);
                  errorCounter++;
              }
          }

          public static void main(String [] args) {
              SchemaFactory schemaFactory =
                      SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");

              ErrorHandler errorHandler = new ErrorHandler();
              schemaFactory.setErrorHandler(errorHandler);

              try {
                  schemaFactory.newSchema(new File(args[0]));
              } catch (SAXException e) {
                  exit(1, "Fatal Error: " + e);
              }

              if (errorHandler.errorCounter == 0) {
                  exit(1, "Failed: " + args[0] + " is valid");
              } else {
                  exit(0, "Passed.");
              }
          }

          public static void exit(int errCode, String msg) {
              System.out.println(msg);
              System.exit(errCode);
          }
      }
      ----------------------------------------------------

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

      Failed: test.xsd is valid
      ----------------------------------------------------

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

            jsuttorsunw Jeff Suttor (Inactive)
            reysunw Rey Rey (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: