You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Raf <ra...@joshua.dreamthought.com> on 2006/03/09 21:52:28 UTC

Commons-Digester - xmlrules - StackOverflowError

Dear All,

I'm having some odd behaviour, which I hoped someone might recognise.

I am using the commons-digester 1.6 with xml rules to populate a config
object.

I have a class, 'Page', which contains a collection of 'Field's.  Some of
these can also be CompoundField's, which are subclasses of Field.  This is
made clearer below.

I have a Junit test which creates a Page, a compound and a field; the test
case seems to instantiate everything correctly without any exceptions.
This does not seem to be the case when I try to use the Digester.

I am trying to Digest an xml tree equivilent to the following:
...
   <page>
	<field name="foo"/>
	<compoundField name="bar">
		<cfield name="bar1"/>
	</compoundField>
   </page>
...

When I leave our my rules to create a compoundField, everything works
fine, however when they are included I get an exception with
StackOverflowError. None of the constructors or mutators used, seem to
cause me to go into any recursion - as proven by my junit test.  The exact
error is of the form:

java.lang.reflect.InvocationTargetException
	at  sun.reflect.NativeMethodAccessorImpl.invoke0( Native Method )
	...
	at org.apache.commons.digester.Digester.parse( Digester.java 1591
)
	...
Caused by: java.lang.StackOverflowError
[ERROR] Digester - -End event threw exception <java.lang.reflect.InvocationTargetException>
	at org.apache.commons.digester.Digester.createSAXException( ... )
	..
	at org.apache.commons.digester.Digester.endElement( .... )
	at ort.apache.commons.digester.Digester.parse( ... )

I have tested this with both commons-digester 1.6 and 1.7.

If I abstract my rules down to the lowest level, my these are as follows(
I have tested at this level of granularity - and failed ) :
<!-------------------------------------------------------->
....
<pattern value="page">
 <object-create-rule classname="foo.model.Page" />
 <!-- a field looks like: -->
 <pattern value="field">
	<object-create-rule classname="foo.model.Field"/>
	<set-next-rule methodname="add"/>

	<call-method-rule methodname="setName" paramcount="1"
paramtypes="java.lang.String"/>
	<call-param-rule paramnumber="0" attrname="name"/>
 </pattern>

 <!-- create a compound -->
 <pattern value="compoundField">
	<!-- note that foo.model.CompoundField extends foo.model.Field -->
	<object-create-rule classname="foo.model.CompoundField"/>
	<set-next-rule methodname="addCompound"/>

	<pattern value="cfield">
	       	<object-create-rule classname="foo.model.Field"/>
	       	<set-next-rule methodname="addMapping"/>

	       	<call-method-rule methodname="setName" paramcount="1"
paramtypes="java.lang.String" />
		<call-param-rule paramnumber="0" attrname="name"/>
	</pattern>

 </pattern>
</pattern>
<!------------------------------------------------------------------>

It might also be worth pointing out that if I comment out the
set-next-rule for addCompound, it also seems to work and I believe that my
tests indicicated that the CompoundField object was still being
instantiated.

Any feedback/similar experience would be appreciated.

Cheers,

Raf


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Commons-Digester - xmlrules - StackOverflowError

Posted by Simon Kitching <sk...@apache.org>.
On Thu, 2006-03-09 at 20:52 +0000, Raf wrote:
> I'm having some odd behaviour, which I hoped someone might recognise.

I can't initially see anything wrong.

I suggest you enable logging output for digester; that should show where
the cause of the problem is. See the logging section of the user guide:
http://jakarta.apache.org/commons/digester/commons-digester-1.7/docs/apidocs/org/apache/commons/digester/package-summary.html

If you still can't understand the problem from the logging output, then
please post both the log output and the complete stacktrace.

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org