Radu Coravu created XERCESJ-1567:
------------------------------------

             Summary: ArrayIndexOutOfBoundsException in XSConstraints
                 Key: XERCESJ-1567
                 URL: https://issues.apache.org/jira/browse/XERCESJ-1567
             Project: Xerces2-J
          Issue Type: Bug
    Affects Versions: 2.11.0
            Reporter: Radu Coravu


I'm integrating "Xerces-J 2.11.0-xml-schema-1.1-beta" in Oxygen XML Editor.

After the integration one of our automated tests caught this 
ArrayIndexOutOfBoundsException:

------------------------
java.lang.ArrayIndexOutOfBoundsException: 2
        at 
org.apache.xerces.impl.xs.XSConstraints.overlapUPA(XSConstraints.java:610)
        at 
org.apache.xerces.impl.xs.XSConstraints.overlapUPA(XSConstraints.java:639)
        at 
org.apache.xerces.impl.xs.models.XSAllCM.checkUniqueParticleAttribution(Unknown 
Source)
        at 
org.apache.xerces.impl.xs.XSConstraints.fullSchemaChecking(XSConstraints.java:481)
        at 
org.apache.xerces.impl.xs.XMLSchemaValidatorXerces.handleEndElement(XMLSchemaValidatorXerces.java:2568)
        at 
org.apache.xerces.impl.xs.XMLSchemaValidatorXerces.endElement(XMLSchemaValidatorXerces.java:922)
        at 
com.thaiopensource.validate.xerces.ValidatorImpl.endElement(ValidatorImpl.java:186)
        at 
com.thaiopensource.validate.nvdl.ValidatorImpl.endElement(ValidatorImpl.java:719)
        at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown 
Source)
--------------------------------------------------

the code where this happens is like:

------------------------------------
        // or if the 2 substitution groups overlap.
        for (int i = subGroup1.length-1; i >= 0; i--) {
            for (int j = subGroup2.length-1; j >= 0; j--) {
                if (subGroup1[i].fName == subGroup2[i].fName &&
                        subGroup1[i].fTargetNamespace == 
subGroup2[i].fTargetNamespace) {
                    return true;
                }
            }
        }

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

So there are two "for" loops but the index in the first loop is used in both 
array entries which are compared.
The code should probably use the "j" index in the second array like:

--------------------------------------
        // or if the 2 substitution groups overlap.
        for (int i = subGroup1.length-1; i >= 0; i--) {
            for (int j = subGroup2.length-1; j >= 0; j--) {
              //OXYGEN PATCH, correctly use index when comparing
                if (subGroup1[i].fName == subGroup2[j].fName &&
                        subGroup1[i].fTargetNamespace == 
subGroup2[j].fTargetNamespace) {
                    return true;
                }
            }
        }
-----------------------------------------

Unfortunately I do not have a simple test for this, we had an automated test 
which validated an XML document against the OOXML XML Schemas available in an 
Oxygen installation.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to