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

Mustang b94 intuduces an XML validation bug. Worked in all previous releases.

    Details

    • Subcomponent:
    • Resolved In Build:
      b96
    • CPU:
      generic, x86
    • OS:
      generic, windows_xp

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0-rc"
      Java(TM) SE Runtime Environment (build 1.6.0-rc-b94)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b94, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      org.xml.sax.SAXParseException: cvc-complex-type.2.4.d: Invalid content was found starting with element '{Tokens}'. No child element is expected at this point.

      This error is spurious. The XML and schema are correct, were OK up to b93, and the Netbeans XML validator is still doing fine.

      The XML is :

      <?xml version="1.0" encoding="UTF-8"?>

      <!--
          Document : examiner.xml
          Created on : August 17, 2004, 2:26 PM
          Author : Amotz Anner
          Description:
              Examiner privilege required ACL.
      -->

      <ACL xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance&#39; xsi:noNamespaceSchemaLocation='file:/C:/XmlApplicLtd/JoXer/XSD/Components.xsd'>
      <Tokens access="full">
      <Token>CheetahTech</Token>
      <Token>CheetahView</Token>
      </Tokens>
      </ACL>

      The schema portion is:

      <?xml version="1.0" encoding="UTF-8"?>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
      <xs:element name="ACL">
      <xs:complexType mixed="false">
      <xs:sequence>
      <xs:element ref="Tokens" maxOccurs="3"/>
      </xs:sequence>
      <xs:attribute name="ACL" type="xs:string" use="optional"/>
      </xs:complexType>
      </xs:element>
      <xs:element name="Tokens">
      <xs:complexType mixed="false">
      <xs:sequence>
      <xs:element ref="Token" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="access" type="xs:string" use="required"/>
      </xs:complexType>
      </xs:element>
      <xs:element name="Token"/>
      </xs:schema>

      This is the relevant part of a much larger schema, which still works well. The only thing special about the {Tokens} definition is the 'maxOccurs="3"' restriction, which is not used elsewhere. The error only occurs if the same schema object is used to validate more than "maxOccurs" documents. Apparently, a counter is not being reset at the start of validation.

      REGRESSION. Last worked in version mustang

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Validate the supplied XML against the supplied schema portion, more than 3 times, using the same schema instance.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No validation error should be found.
      ACTUAL -
      A spurious validation error is found, afetr the third validation.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      org.xml.sax.SAXParseException: cvc-complex-type.2.4.d: Invalid content was found starting with element '{Tokens}'. No child element is expected at this point.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * Main.java
       *
       * Created on August 4, 2006, 10:46 PM
       *
       * To change this template, choose Tools | Template Manager
       * and open the template in the editor.
       */

      package validationerror;

      import java.io.File;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.OutputStream;
      import java.io.OutputStreamWriter;
      import java.io.StringReader;
      import javax.xml.XMLConstants;
      import javax.xml.transform.stream.StreamSource;
      import javax.xml.validation.Schema;
      import javax.xml.validation.SchemaFactory;
      import javax.xml.validation.Validator;
      import org.xml.sax.ErrorHandler;
      import org.xml.sax.SAXException;
      import org.xml.sax.SAXParseException;

      public class Main {
      /** XML */
      public static final String xml = "<ACL xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance&#39;>"+
      "<Tokens access=\"full\">"+
      "<Token>CheetahTech</Token>"+
      "<Token>CheetahView</Token>"+
      "</Tokens>"+
      "</ACL>";
      /** Schema */
      public static final String schema = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
      "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\">"+
      "<xs:element name=\"ACL\">"+
      "<xs:complexType mixed=\"false\">"+
      "<xs:sequence><xs:element ref=\"Tokens\" maxOccurs=\"3\"/></xs:sequence>"+
      "<xs:attribute name=\"ACL\" type=\"xs:string\" use=\"optional\"/>"+
      "</xs:complexType>"+
      "</xs:element><xs:element name=\"Tokens\">"+
      "<xs:complexType mixed=\"false\">"+
      "<xs:sequence><xs:element ref=\"Token\" maxOccurs=\"unbounded\"/></xs:sequence>"+
      "<xs:attribute name=\"access\" type=\"xs:string\" use=\"required\"/>"+
      "</xs:complexType></xs:element><xs:element name=\"Token\"/>"+
      "</xs:schema>";
      /** Schema factory */
      private static final SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);


      /** Creates a new instance of Main */
      public Main() {
      }

      public static void main(String[] args) {
      new Main().test();
      }

      private void test() {
      try {
      final Schema sc = factory.newSchema(writeSchema());
      final Validator validator = sc.newValidator();
      validator.validate(new StreamSource(new StringReader(xml)));
      validator.validate(new StreamSource(new StringReader(xml)));
      validator.validate(new StreamSource(new StringReader(xml)));
      validator.validate(new StreamSource(new StringReader(xml)));
      } catch (Throwable ex) {
      ex.printStackTrace();
      }
      }

      private File writeSchema() throws IOException {
      final File rtn = File.createTempFile("scheam", "xsd");
      final OutputStream out = new FileOutputStream(rtn);
      final OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
      writer.write(schema);
      writer.close();
      out.close();
      return rtn;
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Do not re-use the schema object - but this could slow things down.

      Release Regression From : mustang
      The above release value was the last known release where this
      bug was not reproducible. Since then there has been a regression.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                spericas Santiago Pericasgeertsen
                Reporter:
                rmandalasunw Ranjith Mandala (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: