[ 
https://issues.apache.org/jira/browse/XERCESJ-1279?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12657418#action_12657418
 ] 

Arthur De Magalhaes commented on XERCESJ-1279:
----------------------------------------------

Hi Bill,

I have also worked on this issue, and the patch is being reviewed (also for 
side-effect implications).

One thing I see in the code you posted is that you are adding OneSubGroup 
objects into the Vector, but the hashtable fSubGroupsB assumes that if a Vector 
is returned, it contains the *elements* themselves, not the OneSubGroup 
objects.  So we could run into problems in there.

Here's what I have in my patch:

    public void addSubstitutionGroup(XSElementDecl[] elements) {
        XSElementDecl subHead, element;
        Object subGroup;
        
        // for all elements with substitution group affiliation
        for (int i = elements.length-1; i >= 0; i--) {
            element = elements[i];
            subHead = element.fSubGroup;
            
            // check whether this an entry for this element
            subGroup = fSubGroupsB.get(subHead);
            if (subGroup == null) {
                // if not, create a new one vector to store it
                subGroup = new Vector();
                fSubGroupsB.put(subHead, subGroup);
            }
            
            //Add the element to subGroup, which could be:
            //(1) a OneSubGroup array that was inside the Hashtable 
fSubGroupsB, OR
            //(2) a Vector that was inside the Hashtable fSubGroupsB, OR
            //(3) a new Vector, since nothing was inside the Hashtable 
fSubGroupsB for this elem.
            if (subGroup instanceof OneSubGroup[]){
                //(1), so we need to grow the array and insert the element into 
it
                
                //First we will make our OneSubGroup
                OneSubGroup methods = new OneSubGroup();
                getDBMethods(element.fType, subHead.fType, methods);
                OneSubGroup newOneSubGroup = new OneSubGroup(element, 
methods.dMethod, methods.bMethod);
                
                //Now we will add it to the new array
                int size = ((OneSubGroup[])subGroup).length;
                OneSubGroup[] newSubGroupArray = new OneSubGroup[size + 1];   
                System.arraycopy(subGroup, 0, newSubGroupArray, 0, size);
                newSubGroupArray[size] = newOneSubGroup;
                
                //Place the new array into the Hashtable fSubGroupsB
                fSubGroupsB.put(subHead, newSubGroupArray);

            }
            else{ 
                //(2) or (3), so add element to vector
                ((Vector)subGroup).addElement(element);
            }
        }
    }


> ClassCastException in SubstitutionGroupHandler.addSubstitutionGroup() during 
> Document.normalize()
> -------------------------------------------------------------------------------------------------
>
>                 Key: XERCESJ-1279
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1279
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: XML Schema 1.0 Structures
>    Affects Versions: 2.9.1
>         Environment: Windows, Sun JRE 1.6.00_03
>            Reporter: Bill Michell
>            Assignee: Arthur De Magalhaes
>         Attachments: ContentComponents.xsd, Crash.java, iCI.xsd, test.xml, 
> test.xsd
>
>
> Change 319073 introduced the class SubstitutionGroupHandler$OneSubGroup and 
> the Hashtable fSubGroupB
> According to the documentation, the field has the following characteristics:
>     // to store substitution group information
>     // the key to the hashtable is an element decl, and the value is
>     // - a Vector, which contains all elements that has this element as their
>     //   substitution group affilication
>     // - an array of OneSubGroup, which contains its substitution group 
> before block.
> Unfortuntately, addSubstitutionGroup() contains the following line:
>             subGroup = (Vector)fSubGroupsB.get(subHead);
> This fails with a ClassCastException if the value for the key passed turns 
> out to be a OneSubGroup[]
> The following lines of getSubGroupB() appear to ensure that a OneSubGroup[] 
> is in the map:
>         // Convert to an array
>         OneSubGroup[] ret = new OneSubGroup[newGroup.size()];
>         for (int i = newGroup.size()-1; i >= 0; i--) {
>             ret[i] = (OneSubGroup)newGroup.elementAt(i);
>         }
>         // Store the potential sub group
>         fSubGroupsB.put(element, ret);
>         
>  

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Reply via email to