You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by "Tellis B. Ellis, IV" <te...@oracle.com> on 2006/03/21 18:00:39 UTC

ArrayStoreException in get*Array() method in custom Ant task

Fellow XMLBeans users,
 
I have an xmlbean and some code that uses the xmlbean. The code works as
expected when launched from the java command-line
or launched via Ant's 'java' task. I wrote a simple Ant custom task to
run the code. When the custom task is executed an ArrayStoreException is
thrown in the bean's get*Array() method. I'm using XMLBeans 2.1.0 and
Ant 1.6.4. Below is a snippet from the stacktrace:
 
     java.lang.ArrayStoreException
        at
com.commerce360.internal.cm.starteam.query.xml.impl.QueryDefinitionSetXm
lBeanImpl.getQueryArray(QueryDefinitionSetXmlBeanImpl.java:59)
 
The XSD fragment for the bean looks like this:

	<xs:complexType name="queryDefinitionSet">
	        
	        <xs:sequence>
	            <xs:element ref="query" maxOccurs="unbounded"
minOccurs="0"/>
	        </xs:sequence>
	        
	    </xs:complexType>
	 
	   <xs:complexType name="queryDefinition" abstract="true">
	        
	        <xs:sequence>   
	            
	            <xs:element name="id" type="xs:ID" maxOccurs="1"/>
	 
	        </xs:sequence>
	        
	    </xs:complexType>
	    
	    <xs:complexType name="itemQueryDefinition" abstract="true">
	        <xs:complexContent>
	            <xs:extension base="queryDefinition">          
	                <xs:sequence>
	 
	                </xs:sequence>
	            </xs:extension>
	        </xs:complexContent>
	    </xs:complexType>
	    
	    <xs:complexType name="changeRequestQueryDefinition">
	        <xs:complexContent>
	            <xs:extension base="itemQueryDefinition">          
	                <xs:sequence>
	 
	                </xs:sequence>
	            </xs:extension>
	        </xs:complexContent>
	    </xs:complexType>
	    
	    <xs:complexType name="fileQueryDefinition">
	        <xs:complexContent>
	            <xs:extension base="itemQueryDefinition">          
	                <xs:sequence>
	                    
	                </xs:sequence>
	            </xs:extension>
	        </xs:complexContent>
	    </xs:complexType>
	    
	    <xs:element name="query" type="queryDefinition"/>

The code generated for the xmlbean's getQueryArray() method looks like
this:
 
public class QueryDefinitionSetXmlBeanImpl extends
org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements
com.commerce360.internal.cm.starteam.query.xml.QueryDefinitionSetXmlBean
{
    
    public QueryDefinitionSetXmlBeanImpl(org.apache.xmlbeans.SchemaType
sType)
    {
        super(sType);
    }
    
    private static final javax.xml.namespace.QName QUERY$0 = 
        new
javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/
query/xml", "query");
    private static final org.apache.xmlbeans.QNameSet QUERY$1 =
org.apache.xmlbeans.QNameSet.forArray( 
        new javax.xml.namespace.QName[] { 
        new
javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/
query/xml", "item-query"),
        new
javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/
query/xml", "file-query"),
        new
javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/
query/xml", "change-request-query"),
        new
javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/
query/xml", "query"),
    });
    
    
    /**
     * Gets array of all "query" elements
     */
    public
com.commerce360.internal.cm.starteam.query.xml.QueryDefinitionXmlBean[]
getQueryArray()
    {
        synchronized (monitor())
        {
            check_orphaned();
            java.util.List targetList = new java.util.ArrayList();
            get_store().find_all_element_users(QUERY$1, targetList);
 
com.commerce360.internal.cm.starteam.query.xml.QueryDefinitionXmlBean[]
result = new  
 
com.commerce360.internal.cm.starteam.query.xml.QueryDefinitionXmlBean[ta
rgetList.size()];
            targetList.toArray(result);
            return result;
        }
    }
    
     .....
     .....
     ......
 
}
 
 
 
The exception occurs at the 'targetList.toArray(result)' line. What's
happening is that when the code is run as a custom ant task,
the class of the elements in the 'targetList' ArrayList is
'org.apache.xmlbeans.impl.values.XmlAnyTypeImpl' whereas when the same
code
is successfully run as a command-line java app, the class is
'com.commerce360.internal.cm.starteam.query.xml.impl.ChangeRequestQueryD
efinitionXmlBeanImpl'. I am using the same classpath
and input XML in both cases.
 
I did some googling and found another person who experienced the same
exception but over RMI:
 
http://mail-archives.apache.org/mod_mbox/xmlbeans-user/200310.mbox/%3COF
E6867712.B3D5F68E-ON85256DB4.00559031-85256DB4.005645CE@vrtx.com%3E
 
Does anyone have insight as to why the XMLBeans unmarshalling code would
type my objects as XmlAnyTypeImpl when
run as a custom Ant task? This smells like one of those esoteric
classloader issues and I suspect it requires a deeper knowlegde of
XMLBeans 
internals than I currently have to debug it.
 
Any help or insights would be appreciated.
 
Thanks,
 
-- Tellis

RE: ArrayStoreException in get*Array() method in custom Ant task

Posted by "Tellis B. Ellis, IV" <te...@oracle.com>.
I left out some of the stacktrace:
 
java.lang.ArrayStoreException
        at java.lang.System.arraycopy(Native Method)
        at java.util.ArrayList.toArray(ArrayList.java:305)
        at
com.commerce360.internal.cm.starteam.query.xml.impl.QueryDefinitionSetXm
lBeanImpl.getQueryArray(QueryDefinitionSetXmlBe
anImpl.java:59)
 
 
Thanks,
 
-- Tellis

 
________________________________

From: Tellis B. Ellis, IV [mailto:tellis.ellis@oracle.com] 
Sent: Tuesday, March 21, 2006 11:01 AM
To: user@xmlbeans.apache.org
Subject: ArrayStoreException in get*Array() method in custom Ant task


Fellow XMLBeans users,
 
I have an xmlbean and some code that uses the xmlbean. The code works as
expected when launched from the java command-line
or launched via Ant's 'java' task. I wrote a simple Ant custom task to
run the code. When the custom task is executed an ArrayStoreException is
thrown in the bean's get*Array() method. I'm using XMLBeans 2.1.0 and
Ant 1.6.4. Below is a snippet from the stacktrace:
 
     java.lang.ArrayStoreException
        at
com.commerce360.internal.cm.starteam.query.xml.impl.QueryDefinitionSetXm
lBeanImpl.getQueryArray(QueryDefinitionSetXmlBeanImpl.java:59)
 
The XSD fragment for the bean looks like this:

	<xs:complexType name="queryDefinitionSet">
	        
	        <xs:sequence>
	            <xs:element ref="query" maxOccurs="unbounded"
minOccurs="0"/>
	        </xs:sequence>
	        
	    </xs:complexType>
	 
	   <xs:complexType name="queryDefinition" abstract="true">
	        
	        <xs:sequence>   
	            
	            <xs:element name="id" type="xs:ID" maxOccurs="1"/>
	 
	        </xs:sequence>
	        
	    </xs:complexType>
	    
	    <xs:complexType name="itemQueryDefinition" abstract="true">
	        <xs:complexContent>
	            <xs:extension base="queryDefinition">          
	                <xs:sequence>
	 
	                </xs:sequence>
	            </xs:extension>
	        </xs:complexContent>
	    </xs:complexType>
	    
	    <xs:complexType name="changeRequestQueryDefinition">
	        <xs:complexContent>
	            <xs:extension base="itemQueryDefinition">          
	                <xs:sequence>
	 
	                </xs:sequence>
	            </xs:extension>
	        </xs:complexContent>
	    </xs:complexType>
	    
	    <xs:complexType name="fileQueryDefinition">
	        <xs:complexContent>
	            <xs:extension base="itemQueryDefinition">          
	                <xs:sequence>
	                    
	                </xs:sequence>
	            </xs:extension>
	        </xs:complexContent>
	    </xs:complexType>
	    
	    <xs:element name="query" type="queryDefinition"/>

The code generated for the xmlbean's getQueryArray() method looks like
this:
 
public class QueryDefinitionSetXmlBeanImpl extends
org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements
com.commerce360.internal.cm.starteam.query.xml.QueryDefinitionSetXmlBean
{
    
    public QueryDefinitionSetXmlBeanImpl(org.apache.xmlbeans.SchemaType
sType)
    {
        super(sType);
    }
    
    private static final javax.xml.namespace.QName QUERY$0 = 
        new
javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/
query/xml", "query");
    private static final org.apache.xmlbeans.QNameSet QUERY$1 =
org.apache.xmlbeans.QNameSet.forArray( 
        new javax.xml.namespace.QName[] { 
        new
javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/
query/xml", "item-query"),
        new
javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/
query/xml", "file-query"),
        new
javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/
query/xml", "change-request-query"),
        new
javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/
query/xml", "query"),
    });
    
    
    /**
     * Gets array of all "query" elements
     */
    public
com.commerce360.internal.cm.starteam.query.xml.QueryDefinitionXmlBean[]
getQueryArray()
    {
        synchronized (monitor())
        {
            check_orphaned();
            java.util.List targetList = new java.util.ArrayList();
            get_store().find_all_element_users(QUERY$1, targetList);
 
com.commerce360.internal.cm.starteam.query.xml.QueryDefinitionXmlBean[]
result = new  
 
com.commerce360.internal.cm.starteam.query.xml.QueryDefinitionXmlBean[ta
rgetList.size()];
            targetList.toArray(result);
            return result;
        }
    }
    
     .....
     .....
     ......
 
}
 
 
 
The exception occurs at the 'targetList.toArray(result)' line. What's
happening is that when the code is run as a custom ant task,
the class of the elements in the 'targetList' ArrayList is
'org.apache.xmlbeans.impl.values.XmlAnyTypeImpl' whereas when the same
code
is successfully run as a command-line java app, the class is
'com.commerce360.internal.cm.starteam.query.xml.impl.ChangeRequestQueryD
efinitionXmlBeanImpl'. I am using the same classpath
and input XML in both cases.
 
I did some googling and found another person who experienced the same
exception but over RMI:
 
http://mail-archives.apache.org/mod_mbox/xmlbeans-user/200310.mbox/%3COF
E6867712.B3D5F68E-ON85256DB4.00559031-85256DB4.005645CE@vrtx.com%3E
 
Does anyone have insight as to why the XMLBeans unmarshalling code would
type my objects as XmlAnyTypeImpl when
run as a custom Ant task? This smells like one of those esoteric
classloader issues and I suspect it requires a deeper knowlegde of
XMLBeans 
internals than I currently have to debug it.
 
Any help or insights would be appreciated.
 
Thanks,
 
-- Tellis