commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitri Plotnikov <dmi...@apache.org>
Subject Re: [JXPath] Infinite loop in iterator.hasNext()
Date Thu, 20 Feb 2003 05:14:46 GMT
Steve,

Admittedly, the configuration of JXPath introspection is not too flexible at
this point.  It blindly relies on the BeanInfo data vended by the standard
Introspector, iterating over all "properties" seen by the Introspector.  And
it does not take much for the Introspector to discover a "property".  If you
have something like a getJIType() method, you got yourself a property called
"JIType".  In the perfect world not all getFoo() methods would be treated
the same way.

The only customization the standard Introspector allows is custom BeanInfo.
Unfortunately, you'll have to customize each class' BeanInfo individually -
and that may be a lot of work if you have a lot of classes to customize.  We
have been thinking about improving the situation, this is one of the reasons
we started the Clazz project [see
http://jakarta.apache.org/commons/sandbox/clazz/].  Clazz is currently in
its initial state and JXPath 1.1 is not going to be integrated with it, but
I hope a later release will be.

At this point a custom BeanInfo for each class that has an introspection
problem is the preferred, simple, standard, though not too flexible a
solution - just follow the JavaBeans specification.  Make sure the custom
BeanInfo only declares the properties that are supposed to be declared.   In
your case that does not include "JIType".

There is also a more powerful, though more involved solution that uses
custom NodePointerFactory and NodePointer.  I would not encourage this
solution too much, because NodePointer is a part of internal APIs and so
cannot be relied on too heavily for the long term.

To summarize, I would go with a custom BeanInfo if you want to play it safe
and with custom NodePointer as the last resort if the BeanInfo option does
not work for some reason.

I hope this helps.

- Dmitri

----- Original Message -----
From: "Steve Pannier" <Steve_Pannier.CST@jacada.com>
To: "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
Sent: Wednesday, February 19, 2003 4:08 PM
Subject: Re: [JXPath] Infinite loop in iterator.hasNext()


>
> Dmitri,
>
> I implemented your hack, and I do indeed get the "infinite loop" message.*
>
> I been thinking about this, and the fact that the value objects inside our
> map
> are wrapped inside a custom class is what I think is causing the problem.
> (Our data is organized into a Map-List-Map format, where the value nodes
> (i.e. leaf nodes)  are wrapped in a custom object inside a List.)  When
the
> above "infinite loop" message appears in my logfile, the value of "this"
> shows
> data from within the wrapper class that I wasn't expecting to see.  I've
> done a
> little digging, and I suspect the problem I'm seeing is due to JXPath's
use
> of
> reflection.  I've put some debug statements in
> ValueUtils.getAccessibleValue()
> and ValueUtils.getValue(), and it looks like methods in our custom wrapper
> class are being invoked at the time I encounter the infinite loop problem.
>
> Now, at this point it's still entirely possible there is a "loop"
condition
> within
> our map somewhere.  But I wanted to run this by you before I investigate
> that
> possibility further.  What if the "loop" exists within the bowels of our
> wrapper
> classes.  Is there a way I can prevent JXPath from using reflection to
> interrogate these objects?  Why does JXPath do this?
>
> BTW: I've had no  luck trying to get my test case to recreate this
problem.
> I've duplicated the same map that causes the problem in our application,
> at least from looking at output from map.toString(), but yet it works fine
> in
> my simple test case.  That's why at his point I'm pretty sure it has to do
> with
> the way our data is stored inside the map.
>
> Any thoughts/suggestions?
>
>
> * In the "infinite loop" message in my logfile, the value of "this" is
> shown (below),
> but there's also the following NPE (the "JIType" and "sampleDataModel"
> values
> are what I *wasn't* expecting to see here):
>
> We might be in an infinite loop: /.[@name='more_stuff'][1][@name='cat'][1]
> [@name='toy'][1][@name='
>
#CDATA'][1]/JIType/sampleDataModel/JIType/sampleDataModel/JIType/sampleDataM
odel/JIType/sampleDataModel/JIType/sampleDataModel/JIType/sampleDataModel/JI
Type/sampleDataModel/JIType/sampleDataModel/JIType/sampleDataModel/JIType/sa
mpleDataModel/JIType/sampleDataModel/JIType/sampleDataModel/JIType/sampleDat
aModel/JIType/sampleDataModel/JIType/sampleDataModel/JIType/sampleDataModel/
JIType/sampleDataModel/JIType/sampleDataModel/JIType/sampleDataModel/JIType/
sampleDataModel/JIType/sampleDataModel/JIType/sampleDataModel/JIType/ID
> Exception processing XPath expression: java.lang.NullPointerException
> java.lang.NullPointerException
>      at
>
org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.getPropertyDesc
riptors(BeanPropertyPointer.java:317)
>      at
>
org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.getPropertyDesc
riptor(BeanPropertyPointer.java:302)
>      at
>
org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.getPropertyName
(BeanPropertyPointer.java:282)
>      at
>
org.apache.commons.jxpath.ri.model.beans.PropertyPointer.getName(PropertyPoi
nter.java:110)
>      at
>
org.apache.commons.jxpath.ri.model.NodePointer.asPath(NodePointer.java:647)
>      at
>
org.apache.commons.jxpath.ri.model.NodePointer.toString(NodePointer.java:671
)
>      at java.lang.String.valueOf(String.java:1947)
>      at java.lang.StringBuffer.append(StringBuffer.java:370)
>      at
>
org.apache.commons.jxpath.ri.model.NodePointer.<init>(NodePointer.java:158)
>      at
>
org.apache.commons.jxpath.ri.model.beans.PropertyPointer.<init>(PropertyPoin
ter.java:90)
>      at
>
org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.<init>(BeanProp
ertyPointer.java:89)
>      at
>
org.apache.commons.jxpath.ri.model.beans.BeanPointer.getPropertyPointer(Bean
Pointer.java:113)
>      at
>
org.apache.commons.jxpath.ri.model.beans.PropertyIterator.<init>(PropertyIte
rator.java:94)
>      at
>
org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer.createNodeIter
ator(PropertyOwnerPointer.java:121)
>      at
>
org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer.childIterator(
PropertyOwnerPointer.java:105)
>      at
>
org.apache.commons.jxpath.ri.axes.ChildContext.prepare(ChildContext.java:172
)
>      at
>
org.apache.commons.jxpath.ri.axes.ChildContext.setPosition(ChildContext.java
:147)
>      at
>
org.apache.commons.jxpath.ri.axes.ChildContext.nextNode(ChildContext.java:13
5)
>      at
> org.apache.commons.jxpath.ri.EvalContext.nextSet(EvalContext.java:356)
>      at
>
org.apache.commons.jxpath.ri.axes.PredicateContext.nextSet(PredicateContext.
java:201)
>      at
>
org.apache.commons.jxpath.ri.EvalContext.performIteratorStep(EvalContext.jav
a:192)
>      at
> org.apache.commons.jxpath.ri.EvalContext.hasNext(EvalContext.java:151)
>      at
>
org.apache.commons.jxpath.ri.compiler.Expression$ValueIterator.hasNext(Expre
ssion.java:171)
>      at com.jacada.ji.type.Util.doXPathAssignment(Util.java:862)
>
>
> Thanks again for your help.
>
>
> Steve Pannier
> Jacada, Inc.
> (763) 201-0002 Ext. 219
> spannier@jacada.com
> http://www.jacada.com
>
>
>
> > Steve,
> >
> > I cannot think of any tool that would do that.  There is quick hack
> though.
> > Temporarily change the constructor of NodePointer and do something like
> > this:
> >
> > protected NodePointer(NodePointer parent) {
> >   this.parent = parent;
> >
> > // hack begins here
> >   int length = 0;
> >   NodePointer p = this;
> >   while (p != null){
> >      length  ++;
> >      p = p.getParent();
> >   }
> >   // Now we have the length of the path.  If it is too long, we
> >   // must be in an infinite loop.
> >   if (depth > 100){
> >       System.err.println("We might be in an infinite loop: " + this);
> >   }
> > }
> >
> > This constructor will print a path if it is "too long".
> >
> > I hope this helps.
> >
> > - Dmitri
> >
> > ----- Original Message -----
> > From: "Steve Pannier" <Steve_Pannier.CST@jacada.com>
> > To: "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
> > Sent: Tuesday, February 18, 2003 6:19 PM
> > Subject: Re: [JXPath] Infinite loop in iterator.hasNext()
> >
> >
> > >
> > > Dmitri,
> > >
> > > One thing I forgot to ask in my last post:  I have a Map (or a graph
> > > as you referred to it), and I want to verify that it contains no
loops.
> > > Is there an easy way to do this?  Any tool I can use?  Or do I need
> > > to do this the old fashioned way?
> > >
> > > Thanks for your help.
> > >
> > >
> > > Steve Pannier
> > > Jacada, Inc.
> > > (763) 201-0002 Ext. 219
> > > spannier@jacada.com
> > > http://www.jacada.com
> > >
> > >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>


Mime
View raw message