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

Unexpected SAXException is thrown during validation

XMLWordPrintable

    • b46
    • generic
    • generic
    • Verified

      Name: eaR10174 Date: 03/10/2004


      When the xml document is validated either by ValidatorHanlder or by Validator
      the following exception is thrown:

         SAXException: http://apache.org/xml/properties/internal/entity-resolver

      This exception is thrown when jdk1.5.0-beta2-b41 is used and is not thrown when
      jdk1.5.0-beta2-b40 is used.

      The sample is provided below; it fails on JDK 1.5.0-beta-b41.
      ------------------------------------test.java-----------------------------
      import java.io.ByteArrayInputStream;
      import java.io.InputStreamReader;
      import javax.xml.parsers.SAXParserFactory;
      import javax.xml.transform.stream.StreamSource;
      import javax.xml.validation.Schema;
      import javax.xml.validation.SchemaFactory;
      import javax.xml.validation.ValidatorHandler;
      import javax.xml.validation.Validator;
      import org.xml.sax.Attributes;
      import org.xml.sax.InputSource;
      import org.xml.sax.SAXException;
      import org.xml.sax.XMLReader;
      import org.xml.sax.helpers.DefaultHandler;


      public class test {
           public static final String XSD = "<?xml version='1.0'?>\n"
                   + "<schema xmlns='http://www.w3.org/2001/XMLSchema&#39;\n"
                   + " xmlns:test='jaxp13_test'\n"
                   + " targetNamespace='jaxp13_test'>\n"
                   + " <element name='test'>\n"
                   + " <complexType>\n"
                   + " <sequence>\n"
                   + " <element name='child' type='string'/>\n"
                   + " </sequence>\n"
                   + " <attribute name='id' type='ID'/>\n"
                   + " </complexType>\n"
                   + " </element>\n"
                   + "</schema>\n";

           public static final String XML = "<?xml version='1.0'?>\n"
                       + "<?test v01?>\n"
                       + "<ns:test xmlns:ns='jaxp13_test' id='i001'>\n"
                       + " <child>123abc</child>\n"
                       + "</ns:test>\n";

           private ValidatorHandler validatorHandler;
           private Validator validator;

           private XMLReader createXMLReader() throws Exception {
               SAXParserFactory parserFactory = SAXParserFactory.newInstance();
               parserFactory.setNamespaceAware(true);

               return parserFactory.newSAXParser().getXMLReader();
           }

           void createValidators(String xsd)
                   throws Exception {
               SchemaFactory schemaFactory =
                   SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");

               InputStreamReader reader =
                   new InputStreamReader(new ByteArrayInputStream(xsd.getBytes()));
               StreamSource xsdSource = new StreamSource(reader);

               Schema schema = schemaFactory.newSchema(xsdSource);

               this.validatorHandler = schema.newValidatorHandler();
               this.validator = schema.newValidator();
           }

           private void parse(XMLReader xmlReader, String xml) throws Exception {
               InputStreamReader reader =
                   new InputStreamReader(new ByteArrayInputStream(xml.getBytes()));
               InputSource inSource = new InputSource(reader);

               xmlReader.parse(inSource);
           }

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

               try {
                   System.out.println("Running test case 1.");
                   t.run1();
                   System.out.println("OK.");
               } catch (Exception e) {
                   e.printStackTrace();
               }

               try {
                   System.out.println("\nRunning test case 2.");
                   t.run2();
                   System.out.println("OK.");
               } catch (Exception e) {
                   e.printStackTrace();
               }
           }

           public void run1() throws Exception {
               DefaultHandler contentHandler = new DefaultHandler();
               validatorHandler.setContentHandler(contentHandler);
               validatorHandler.setErrorHandler(contentHandler);

               XMLReader xmlReader = createXMLReader();
               xmlReader.setContentHandler(validatorHandler);
               parse(xmlReader, XML);
           }

           public void run2() throws Exception {
               InputStreamReader reader =
                   new InputStreamReader(new ByteArrayInputStream(XML.getBytes()));
               StreamSource xmlSource = new StreamSource(reader);

               validator.validate(xmlSource);
           }
      }
      --------------------------------------------------------------------------
      % java -showversion test
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b41)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b41, mixed mode)

      Running test case 1.
      org.xml.sax.SAXException: http://apache.org/xml/properties/internal/entity-resolver
      at
      com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1218)
      at test.parse(test.java:64)
      at test.run1(test.java:100)
      at test.main(test.java:78)

      Running test case 2.
      org.xml.sax.SAXException: http://apache.org/xml/properties/internal/entity-resolver
      at
      com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1218)
      at
      com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.process(ValidatorImpl.java:191)
      at
      com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:158)
      at javax.xml.validation.Validator.validate(Validator.java:64)
      at test.run2(test.java:107)
      at test.main(test.java:86)
      --------------------------------------------------------------------------

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

      api/javax_xml/validation/ValidatorHandler/index.html#GetSetContentHandler[GetSetContentHandler004]
      api/javax_xml/validation/ValidatorHandler/index.html#GetSetContentHandler[GetSetContentHandler008]
      api/javax_xml/validation/ValidatorHandler/index.html#GetSetContentHandler[GetSetContentHandler009]
      api/javax_xml/validation/ValidatorHandler/index.html#GetSetContentHandler[GetSetContentHandler010]
      api/javax_xml/validation/Validator/index.html#Validate[Validate001]
      api/javax_xml/validation/Validator/index.html#Validate[Validate004]
      api/javax_xml/validation/Validator/index.html#Validate[Validate005]
      api/javax_xml/validation/Validator/index.html#Validate[Validate006]
      api/javax_xml/validation/Validator/index.html#Validate[Validate007]
      api/javax_xml/validation/Validator/index.html#Validate[Validate008]
      api/javax_xml/validation/Validator/index.html#Validate[Validate016]
      api/javax_xml/validation/Validator/index.html#Validate[Validate017]
      api/javax_xml/validation/ValidatorHandler/index.html#GetTypeInfoProvider
      api/javax_xml/validation/SchemaFactory/index.html#NewSchema[NewSchema002]
      api/javax_xml/validation/SchemaFactory/index.html#NewSchema[NewSchema003]
      api/javax_xml/validation/SchemaFactory/index.html#NewSchema[NewSchema004]
      api/javax_xml/validation/SchemaFactory/index.html#NewSchema[NewSchema005]
      api/javax_xml/validation/SchemaFactory/index.html#NewSchema[NewSchema006]
      api/javax_xml/validation/SchemaFactory/index.html#NewSchema[NewSchema014]
      api/javax_xml/validation/SchemaFactory/index.html#NewSchema[NewSchema017]
      api/javax_xml/validation/SchemaFactory/index.html#NewSchema[NewSchema020]
      api/javax_xml/validation/SchemaFactory/index.html#NewSchema[NewSchema023]
      api/javax_xml/validation/ValidatorHandler/index.html#GetSetErrorHandler[GetSetErrorHandler005]
      api/javax_xml/validation/TypeInfoProvider/index.html#GetElementTypeInfo
      api/javax_xml/validation/TypeInfoProvider/index.html#GetAttrTypeInfo
      api/javax_xml/validation/ValidatorHandler/index.html#GetSetFeature[GetSetFeature009]
      api/javax_xml/validation/TypeInfoProvider/index.html#IsIdAttribute
      api/javax_xml/validation/TypeInfoProvider/index.html#IsSpecified


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

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: