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

validation.SchemaFactory: xpath="@" causes MissingResourceException

XMLWordPrintable

    • b46
    • generic
    • generic
    • Verified

      Name: erR10175 Date: 03/09/2004



         The method

      public Schema newSchema(File schema)

      in the class javax.xml.validation.SchemaFactory throws
      java.util.MissingResourceException which is not an instance of SAXException.

      According to the javadoc, the method is allowed to throw SAXException or
      NullPointerException. So it is an error to throw MissingResourceException.

      The bug affects the following new JCK-15 beta2 test adopted from W3C XSTC-20020116 testsuite:
           api/xml_schema/msxsdtest/identityConstraint/idJ002.html#idJ002

      The bug is found in jdk1.5.0/beta/b41 and it is not reproducible with jdk1.5.0/beta/b40.

      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="root">
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="tid" maxOccurs="unbounded"/>
      </xsd:sequence>
      </xsd:complexType>
      <xsd:unique id="foo123" name="uid">
      <xsd:selector xpath=".//tid"/>
      <xsd:field xpath="@"/>
      </xsd:unique>
      </xsd:element>
      </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-b41)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b41, mixed mode)

      Exception in thread "main" java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key c-xpath-general
               at java.util.ResourceBundle.getObject(ResourceBundle.java:314)
               at java.util.ResourceBundle.getString(ResourceBundle.java:274)
               at com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter.formatMessage(XSMessageFormatter.java:113)
               at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:344)
               at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaError(XSDHandler.java:2241)
               at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDAbstractTraverser.reportSchemaError(XSDAbstractTraverser.java:612)
               at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDAbstractIDConstraintTraverser.traverseIdentityConstraint(XSDAbstractIDConstraintTraverser.java:190)
               at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDUniqueOrKeyTraverser.traverse(XSDUniqueOrKeyTraverser.java:110)
               at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDElementTraverser.traverseNamedElement(XSDElementTraverser.java:405)
               at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDElementTraverser.traverseGlobal(XSDElementTraverser.java:248)
               at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.traverseSchemas(XSDHandler.java:1081)
               at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:481)
               at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:558)
               at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:525)
               at com.sun.org.apache.xerces.internal.jaxp.validation.xs.SchemaFactoryImpl.newSchema(SchemaFactoryImpl.java:165)
               at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:429)
               at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:445)
               at test.main(test.java:31)
      ----------------------------------------------------

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

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: