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

newSchema: catched exception is not equal to exception thrown from ResourceResol

XMLWordPrintable

    • generic
    • generic



      Name: eaR10174 Date: 02/20/2004


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

            public abstract void setResourceResolver(LSResourceResolver resourceResolver)

            ...
            If a LSResourceResolver throws a RuntimeException (or instances of its derived classes),
            then the SchemaFactory will abort the parsing and the caller of the newSchema method will
            receive the same RuntimeException.

      The bug affects the new JCK1.5-beta1 test:

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

      This test has been in the known failures list with the bug #4969089.

      The sample is provided below; it fails on JDK 1.5.0-beta-b39.
      ------------------------------------test.java-----------------------------
      import java.io.StringReader;
      import javax.xml.transform.stream.StreamSource;
      import javax.xml.transform.Source;
      import javax.xml.validation.SchemaFactory;
      import org.w3c.dom.ls.LSInput;
      import org.w3c.dom.ls.LSResourceResolver;


      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"
                           + " <import namespace='jaxp13_test2'/>\n"
                           + " <element name='test'/>\n"
                           + " <element name='child1'/>\n"
                           + "</schema>\n";

               final NullPointerException npe = new NullPointerException("NewSchema015");
               SchemaFactory schemaFactory =
                     SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
               StringReader reader = new StringReader(xsd1);
               StreamSource source = new StreamSource(reader);
               LSResourceResolver resolver = new LSResourceResolver() {
                   public LSInput resolveResource(String type, String namespaceURI,
                           String publicId, String systemId, String baseURI) {
                       LSInput input;
                       if (namespaceURI != null && namespaceURI.endsWith("jaxp13_test2")) {
                           throw npe;
                       } else {
                           input = null;
                       }

                       return input;
                   }
               };
               schemaFactory.setResourceResolver(resolver);

               try {
                   schemaFactory.newSchema(new Source[] {source});
                   System.out.println("NullPointerException was not thrown.");
               } catch (Exception e) {
                   if (npe == e) {
                       System.out.println("OK");
                   } else {
                       System.out.println("The exceptions are not the same: ");
                       System.out.println("catched exc. hashCode=" + e.hashCode());
                       System.out.println("expected exc. hashCode=" + npe.hashCode());
                   }
               }
           }
      }
      --------------------------------------------------------------------------
      % java -showversion test
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b39)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b39, mixed mode)

      The exceptions are not the same:
      catched exc. hashCode=25609906
      expected exc. hashCode=22996593
      --------------------------------------------------------------------------

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

            Unassigned Unassigned
            evgsunw Evg Evg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: