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

Message in SAXParseException contains incorrect URL in URI

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 5.0u2
    • Component/s: xml
    • Subcomponent:
    • Resolved In Build:
      b04
    • CPU:
      x86
    • OS:
      windows_xp
    • Verification:
      Verified

      Description

      import javax.xml.parsers.SAXParser;
      import javax.xml.parsers.SAXParserFactory;
      import javax.xml.parsers.*;
      import java.io.*;
      import org.xml.sax.SAXParseException;
      import javax.xml.validation.*;
      /**
       *
       * @author Neeraj Bajaj, Sun Microsystems.
       *
       */
      public class Test {
          
          static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
          static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
          static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
          
          /** Creates a new instance of Test */
          public Test() {
              //super(name);
          }
          public void test2() throws Exception{
              boolean passed = true;
              try{
                  DocumentBuilderFactory factory = DocumentBuilderFactory
                          .newInstance();
                  factory.setNamespaceAware(true);
                  SchemaFactory sfactory = SchemaFactory.newInstance(W3C_XML_SCHEMA);
      Schema schema = sfactory.newSchema(new File(JAXP_SCHEMA_SOURCE));
                  factory.setSchema(schema);
                  DocumentBuilder builder = factory.newDocumentBuilder();
                  String TEST_1b = "XML with bad content in an element";
                  byte[] b = TEST_1b.getBytes();
                  ByteArrayInputStream stringStream = new ByteArrayInputStream(b);
                  builder.parse(stringStream);
              }catch(SAXParseException se){
                  System.out.println("Exception "+se );
      passed = false;

      }catch(Exception e){
                  System.out.println("Exception "+e);
                  passed = false;
      }
              
          }
          
          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
      try{
              new Test().test2();
             }catch(Exception e){
      System.out.println("Exception got" +e);
            }
          }
          
      }

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]
      (probably not OS specific)

      A DESCRIPTION OF THE PROBLEM :
      When an XML document fails an XML-schema- validated parse due to bad content in an element, the full message in the SAX exception is:
      http://www.w3.org/TR/xml-schema-1#cvc-datatype-valid.1.2.1?...
      where the "..." represents some specific information. One is tempted to use the characters to the left of the "?" as a URL for the specific part of the schema specification that the document violated. However, the closest URL for a specification is
      http://www.w3.org/TR/xmlschema-1
      (no dash between "xml" and "schema"). Even in this case, the internal document tag does not exist. A more precise URL for this violation would be
      http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/datatypes.html#cvc-datatype-valid

      Although I have not made an exhaustive evaluaton of the SAXParseException messages, I suspect that many/all of them contain a possibly misleading URI. Since this is the only message included in the exception, it would seem desirable to have a more accurate URL embedded in the message, to allow one to better isolate the precise problem with the XML document.

      This situation may have existed in previous releases. However, in previous releases the SAXParseException would often contain a quote from the specification, making the URI less important in error tracking.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
                  Schema schema = ...;
                  DocumentBuilderFactory factory = DocumentBuilderFactory
                          .newInstance();
                  factory.setNamespaceAware(true);
                  factory.setSchema(schema);
                  DocumentBuilder builder = factory.newDocumentBuilder();
                  String TEST_1b = "XML with bad content in an element";
                  byte[] b = TEST_1b.getBytes();
                  ByteArrayInputStream stringStream = new ByteArrayInputStream(b);
                  builder.parse(stringStream);

      catch the SAXParseException and print out the message

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I was expecting a more meaningful error message in the SAXParseException
      ACTUAL -
      Expected SAX parse exception in image
      Line number: 16
      Col number: 25
        Public/System id: null/null
      Message: http://www.w3.org/TR/xml-schema-1#cvc-datatype-valid.1.2.1?x&decimal


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      See result above

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      See reproduction steps above
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Creative re-writing of the URL in the error message URI
      ###@###.### 10/11/04 08:03 GMT
      ###@###.### 2004-12-21 09:46:27 GMT

        Attachments

          Activity

            People

            Assignee:
            jsuttorsunw Jeff Suttor (Inactive)
            Reporter:
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: