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

newSchema: thrown exception is not equal to exception thrown from ErrorHandler

    Details

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

      Backports

        Description

        Name: eaR10174 Date: 12/16/2003


           The javax.xml.validation.SchemaFactory.newSchema(Source[]) method throws an exception that is not
        equal to the exception thrown from ErrorHandler (see test.java below). The exceptions should be the
        same according to the javadoc:

             public abstract Schema newSchema(javax.xml.transform.Source[] schemas)
                                   throws org.xml.sax.SAXException

             ...
             When an ErrorHandler is set, the callee will report all the errors found in sources
             to the handler. If the handler throws an exception, it will abort the schema
             compilation and the same exception will be thrown from this method.

        The bug appears in jdk1.5.0beta-b31 and affects new JCK1.5 tests (not integrated yet):

           api/javax_xml/validation/SchemaFactory/index.html#NewSchema[NewSchema007]
           api/javax_xml/validation/SchemaFactory/index.html#NewSchema[NewSchema015]

        ------------------------------------test.java-----------------------------
        import java.io.StringReader;
        import javax.xml.transform.stream.StreamSource;
        import javax.xml.transform.Source;
        import javax.xml.validation.SchemaFactory;
        import org.xml.sax.SAXException;
        import org.xml.sax.SAXParseException;
        import org.xml.sax.helpers.DefaultHandler;


        public class test {

              public static void main(String argv[]) {
                  try {
                      new test().run();
                  } catch (Exception e) {
                      e.printStackTrace();
                      System.exit(1);
                  }
              }

              public void run() {
                  String xsd1 = "<?xml version='1.0'?>\n"
                              + "<schema xmlns='http://www.w3.org/2001/XMLSchema&#39;\n"
                              + " xmlns:test='jaxp13_test1'\n"
                              + " targetNamespace='jaxp13_test1'\n"
                              + " elementFormDefault='qualified'>\n"
                              + " <element name='test'>\n"
                              + "</schema>\n";

                  final SAXException exc = new SAXException("NewSchema007");
                  SchemaFactory schemaFactory =
                      SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
                  StringReader reader = new StringReader(xsd1);
                  StreamSource source = new StreamSource(reader);
                  DefaultHandler errorHandler = new DefaultHandler() {
                      public void fatalError(SAXParseException exception) throws SAXException {
                          throw exc;
                      }

                      public void error(SAXParseException exception) throws SAXException {
                          fatalError(exception);
                      }
                  };
                  schemaFactory.setErrorHandler(errorHandler);

                  try {
                      schemaFactory.newSchema(new Source[] {source});
                      System.out.println("SAXException was not thrown.");
                  } catch (SAXException e) {
                      if (exc == e) {
                          System.out.println("OK");
                      } else {
                          System.out.println("The exception is not as expected.");
                      }
                  }
              }
        }
        --------------------------------------------------------------------------
        % java -showversion test
        java version "1.5.0-beta"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b31)
        Java HotSpot(TM) Client VM (build 1.5.0-beta-b31, mixed mode)

        The exception is not as expected.
        --------------------------------------------------------------------------

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

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  kkawagucsunw Kohsuke Kawaguchi (Inactive)
                  Reporter:
                  evgsunw Evg Evg (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: