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

java.util.MissingResourceException is thrown from SAXParser.setProperty()

    Details

    • Subcomponent:
    • Resolved In Build:
      1.3
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        Name: inR10064 Date: 04/30/2004



        The fix of
            5025825: SAXParser allows Schema and the 'schemaLanguage' prop

        isn't fully completed - some resource for the error reporting seems to be missed.
        Details of the tested case are described in #5025825.

        The same new tests in JCK 1.5 :
          api/javax_xml/parsers/SAXParserFactory/index.html#SetSchema[SetSchema401]
          api/javax_xml/parsers/SAXParserFactory/index.html#SetSchema[SetSchema402]

        are still failing due to this bug.

        The bug is reproducible with the JDK 1.5.0-beta-b49 (please see the sample code
        and log below).

        ------------------------------- SetSchema402.java
        package tests;

        import java.io.StringReader;
        import javax.xml.XMLConstants;
        import javax.xml.parsers.SAXParser;
        import javax.xml.parsers.SAXParserFactory;
        import javax.xml.parsers.ParserConfigurationException;
        import javax.xml.transform.stream.StreamSource;
        import javax.xml.validation.Schema;
        import javax.xml.validation.SchemaFactory;
        import org.xml.sax.InputSource;
        import org.xml.sax.SAXException;

        public class SetSchema402 {

            String schemaSource =
                              "<?xml version='1.0'?>\n"
                              + "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema&#39;>\n"
                              + " <xsd:element name='test101'>\n"
                              + " <xsd:complexType>\n"
                              + " <xsd:attribute name='attr'/>\n"
                              + " <xsd:attribute name='attr2' default='DEF'/>\n"
                              + " </xsd:complexType>\n"
                              + " </xsd:element>\n"
                              + "</xsd:schema>\n";

            Schema createSchema() {
                SchemaFactory schFactory = SchemaFactory.newInstance(
        XMLConstants.W3C_XML_SCHEMA_NS_URI);
        try {
        Schema sch = schFactory.newSchema(
        new StreamSource(
        new StringReader(schemaSource)
        ));
        return sch;
        } catch (Exception se) {
        throw new IllegalStateException("No Schema : " + se);
        }
            }

            void setAttr(boolean setSrc) {
                Schema sch = createSchema();
                SAXParserFactory spFactory = SAXParserFactory.newInstance();
                spFactory.setNamespaceAware(true);
                spFactory.setValidating(true);
                spFactory.setSchema(sch);

                SAXParser sParser = null;
                try {
                    sParser = spFactory.newSAXParser();
                } catch (Exception pce) {
                    pce.printStackTrace();
                    return;
                }

                final String aSchemaLanguage =
        "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
        final String aSchemaSource = "http://java.sun.com/xml/jaxp/properties/schemaSource";

                try {
                    sParser.setProperty(aSchemaLanguage, "http://www.w3.org/2001/XMLSchema");
        System.out.println("---- Set schemaLanguage: "+
        sParser.getProperty(aSchemaLanguage));
                } catch (SAXException e) {
                    System.out.println("== "+ e);
                }

        if (! setSrc)
        return;

                try {
                   sParser.setProperty(aSchemaSource,
                                            new InputSource(new StringReader(schemaSource)));
        System.out.println("---- Set schemaSource: "+ sParser.getProperty(aSchemaSource));
                } catch (SAXException e) {
                    System.out.println("== "+ e);
                }
            }

            public static void main(String argv[]) {
        SetSchema402 test = new SetSchema402();
        test.setAttr(false);
        test.setAttr(true);
            }

        }

        --------------------------------------------------------------------------
        % java -showversion -cp . tests/SetSchema402
        java version "1.5.0-beta2"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b49)
        Java HotSpot(TM) Server VM (build 1.5.0-beta2-b49, mixed mode)

        Exception in thread "main" java.util.MissingResourceException: schema-already-specified
                at
        com.sun.org.apache.xerces.internal.util.SAXMessageFormatter.formatMessage(SAXMessageFormatter.j
        ava:120)
                at
        com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:223)
                at tests.SetSchema402.setAttr(SetSchema402.java:60)
                at tests.SetSchema402.main(SetSchema402.java:80)

        --------------------------------------------------------------------------

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

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: