JDK-4674384 : Big value of maxOccurs of element declaration causes StackOverflowError
  • Type: Bug
  • Component: xml
  • Sub-Component: org.xml.sax
  • Affected Version: 1.2.0,5.0
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2002-04-25
  • Updated: 2024-11-19
  • Resolved: 2006-09-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b81Fixed
Related Reports
Relates :  
Relates :  
Description
Name: eaR10174			Date: 04/25/2002


 The following valid schema and valid xml document causes java.lang.StackOverflowError
   
------------------------------------test.xsd-----------------------------
<?xml version="1.0"?>

<xsd:schema
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns="test"
  targetNamespace="test">

     <xsd:element name="a" type="A"/>
     <xsd:complexType name="A">
          <xsd:sequence>
	       <xsd:element name="b" type="xsd:string" maxOccurs="3000"/>
	  </xsd:sequence>
     </xsd:complexType>

</xsd:schema>
-------------------------------------------------------------------------
------------------------------------test.xml-----------------------------
<?xml version="1.0"?>
<test:a
    xmlns:test="test"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="test test.xsd">
<b>1</b>
<b>2</b>
</test:a>
-------------------------------------------------------------------------

  Note the value of the attribute 'maxOccurs' is equal to 3000 which seems
lead to the failure. If the value is set to less number the sample passes but
spends innormal amount of time to parse the document (see table below).
  
  maxOccurs |   time    | status
 --------------------------------
   100      | 0m5.438s  | passed
   1000     | 0m15.350s | passed
   2000     | 1m31.740s | passed
   3000     | 2m49.279s | failed (StackOverflowError)

The time results were measured for 
     - SUNW, Ultra-2; sparc; sun4u; RAM - 512M; 1 processor; Solaris 8 

configuration.

The test has also failed on the following machines:

   - SUNW, Ultra-Enterprise; sparc; sun4u; RAM - 512M; 4 processors; Solaris 7
   - Dell PowerEdge 2300; Pentium II 350MHz; RAM -512M; 2 processors; WinNT 4.0 Server

This bug is found in jaxp-1.2.0-fcs-b14-10_apr_2002 and affects the new JAXP TCK 1.2 tests

 api/xml_schema/structures/MGroup/compositor/compositor00101m/compositor00101m2.html

Do the following steps to reproduce this bug:

1. Save test.xsd and test.xml
2. Save the following TestRun.java

------------------------------------TestRun.java-------------------------
import java.io.File;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import org.xml.sax.helpers.DefaultHandler;

public class TestRun {

    public static void main(String [] args) {
        try {
            // create and initialize the parser
            SAXParserFactory spf = SAXParserFactory.newInstance();
            spf.setNamespaceAware(true);
            spf.setValidating(true);
            SAXParser parser = spf.newSAXParser();

            parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
                               "http://www.w3.org/2001/XMLSchema");

            File xmlFile = new File(args[0]);
            parser.parse(xmlFile, new DefaultHandler());

            System.out.println("Passed.");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Failed.");
        }
    }
}
-------------------------------------------------------------------------

3. Set CLASSPATH

   % export CLASSPATH=.:$JAXP_HOME/dom.jar:$JAXP_HOME/dom.jar:     $JAXP_HOME/sax.jar:$JAXP_HOME/jaxp-api.jar:$JAXP_HOME/xalan.jar:     $JAXP_HOME/xercesImpl.jar

4. Compile TestRun.java

   % javac TestRun.java

5. Run the test

   % java -showversion TestRun test.xml


I got the following result when I set the value of the attribute 'maxOccurs' to 3000: 

java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

Exception in thread "main" java.lang.StackOverflowError
  at org.apache.xerces.impl.dtd.models.CMNode.firstPos(CMNode.java:96)
  at org.apache.xerces.impl.xs.models.XSCMBinOp.calcFirstPos(XSCMBinOp.java:136)
  at org.apache.xerces.impl.dtd.models.CMNode.firstPos(CMNode.java:97)
  at org.apache.xerces.impl.xs.models.XSCMBinOp.calcFirstPos(XSCMBinOp.java:136)
  at org.apache.xerces.impl.dtd.models.CMNode.firstPos(CMNode.java:97)
  at org.apache.xerces.impl.xs.models.XSCMBinOp.calcFirstPos(XSCMBinOp.java:136)
  at org.apache.xerces.impl.dtd.models.CMNode.firstPos(CMNode.java:97)
  at org.apache.xerces.impl.xs.models.XSCMBinOp.calcFirstPos(XSCMBinOp.java:136)
  at org.apache.xerces.impl.dtd.models.CMNode.firstPos(CMNode.java:97)
  at org.apache.xerces.impl.xs.models.XSCMBinOp.calcFirstPos(XSCMBinOp.java:136)
  at org.apache.xerces.impl.dtd.models.CMNode.firstPos(CMNode.java:97)
  at org.apache.xerces.impl.xs.models.XSCMBinOp.calcFirstPos(XSCMBinOp.java:136)
  at org.apache.xerces.impl.dtd.models.CMNode.firstPos(CMNode.java:97)
  at org.apache.xerces.impl.xs.models.XSCMBinOp.calcFirstPos(XSCMBinOp.java:136)
  ...

======================================================================
###@###.### 11/2/04 22:00 GMT

Comments
EVALUATION this is a very old bug. a unit test has been created and it has been tested against the JAXP for Mustang b81 and it passes. maxOccurs == 10,000 were tested.
13-04-2006

SUGGESTED FIX test w/latest JAXP 1.4 to see if last Apache merge changed behavior. if note, this is an architectural issues and this CR should be targeted for JAXP 2.0.
12-04-2006

EVALUATION This is known LIMITATION in Xerces. There is similar bug filed in bugzilla http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6818 There is workaround for this problem which works in most of the cases. Replace the "maxOccurs" value to "unbounded" . It might be problematic for those application which want high and *fixed* number of occurences, say 4500 or any such fixed number. There are other known schema limitation in Xerces2 http://xml.apache.org/xerces2-j/limitations-schema.html which i feel should also be documented or perhaps a link to it. But i failed to find if above limitation is documented in Xerces2. I consider to add it in Xerces2 list of know limitations. It requires re-designing of the way content model works. It is among part of things in Xerces2 that have to be REVISITED. ###@###.### 2002-04-25 This bug was deliberatly left in Xerces 2 and exists from Xerces 1. It was never a priority requirement by any application and so by xerces developers b/c it works perfectly fine with "maxOccurs = unbounded". So, It should never be a P2 or P3 bug. I talked to Tom Kincaid and he was OK to lower the priority.
11-06-2004