commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joseph Campolongo <JCampolo...@cra.com>
Subject RE: [JXPath] StackOverflow error
Date Fri, 19 May 2006 17:08:59 GMT
I have continued looking into this, and found that the problem is that, if
the List is created with a 'null' element, JXPath gets stuck in infinite
recursion.

To discover this, I changed my Factory to implement the following method:

      public boolean createObject(
          JXPathContext context, Pointer pointer, Object parent, 
          String name, int index) {

        if (pointer instanceof NodePointer) {
          index = ((NodePointer)pointer).getIndex();
        }
        System.out.println(parent + ":" + name + ":" + index);
        Map parentMap = (Map)parent;
        if (index > -1) {
          List list = (List)parentMap.get(name);
          if (list == null) {
            list = new ArrayList();
          }
          int size = list.size();
          for (int i = size; i <= index; i++) {
            list.add(i, new HashMap());  // !!!!!!  Don't set to 'null'
          }
          parentMap.put(name, list);
        } else {
          parentMap.put(name, new HashMap());
        }
        return true;
      }

Then I ran the following code:

    pathContext.createPath("a/b[1]/c");
    pathContext.createPath("a/b[2]/c");  // STACK OVERFLOW HERE

Here is the stack trace at the beginning, where
'ValueUtils.expandCollection()' is called.  It puts 'null' into the list,
thus causing the stack overflow as we cycle between createPath() &
createChild().

Thread [main] (Suspended (breakpoint at line 227 in DynamicPropertyPointer))
	DynamicPropertyPointer.createPath(JXPathContext) line: 227
	DynamicPropertyPointer(PropertyPointer).createChild(JXPathContext,
QName, int) line: 188
	NullElementPointer.createPath(JXPathContext) line: 82
	NullPointer.createPath(JXPathContext) line: 86
	NullPropertyPointer.createPath(JXPathContext) line: 103
	NullPointer.createPath(JXPathContext) line: 86
	NullPropertyPointer.createPath(JXPathContext) line: 103
	JXPathContextReferenceImpl.createPath(String, Expression) line: 447
	JXPathContextReferenceImpl.createPath(String) line: 427
	Test.test4() line: 75
	Test.main(String[]) line: 38

This looks like a bug to me, but I certainly could be missing something
here.

Joseph Campolongo

-----Original Message-----
From: Joseph Campolongo [mailto:JCampolongo@cra.com]
Sent: Friday, May 19, 2006 11:12 AM
To: commons-user@jakarta.apache.org
Subject: [JXPath] StackOverflow error


I'm running into a StackOverflow error on a call to
'JXPathContext.createPath()' whenever I have a path that looks like
'a/b[1]/c'.  I took a quick look at the code and it appears JXPath, when
trying to create its parent pointer, simply recreates an equivalent
pointer(???).

I'm not sure if my AbstractFactory is incorrect, if JXPath simply doesn't
handle the above case(s), or if this is actually a bug in JXPath.

Here is code to reproduce the problem.


    Map map = new HashMap();
    map.put("a", null);
    
    JXPathContext pathContext = JXPathContext.newContext(map);
    pathContext.setFactory(new AbstractFactory() {
      public boolean createObject(
          JXPathContext context, Pointer pointer, Object parent, String
name, int index) {

        Map parentMap = (Map)parent;
        System.out.println(parent + ":" + name + ":" + index);
        if (index > -1) {
          List list = (List)parentMap.get(name);
          if (list == null) {
            list = new ArrayList();
          }
          int size = list.size();
          for (int i = size; i <= index; i++) {
            list.add(i, null);
          }
          parentMap.put(name, list);
        } else {
          parentMap.put(name, new HashMap());
        }
        return true;
      }
      
    });
    pathContext.createPath("a/b[1]/c");
    
Joseph Campolongo



Mime
View raw message