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] StackOverflowError with xpath to Map object
Date Sat, 19 Mar 2005 21:11:21 GMT
Scott,

After I added that additional vector to the vector, I was able to reproduce 
the problem you reported.

I fixed the issue by implementing the method CollectionPointer.testNode as 
follows:

    public boolean testNode(NodeTest test) {
        if (index == WHOLE_COLLECTION) {
            if (test == null) {
                return true;
            }
            else if (test instanceof NodeNameTest) {
                return false;
            }
            else if (test instanceof NodeTypeTest) {
                if (((NodeTypeTest) test).getNodeType() == 
Compiler.NODE_TYPE_NODE) {
                    return true;
                }
            }
            return false;
        }
        return getValuePointer().testNode(test);
    }

Now this test case seems to work correctly:

    /**
     * Scott Heaberlin's test - collection of collections
     */
    public void testCollectionPointer() {
        List list = new ArrayList();
        Map map = new HashMap();
        map.put("KeyOne", "SomeStringOne");
        map.put("KeyTwo", "SomeStringTwo");

        Map map2 = new HashMap();
        map2.put("KeyA", "StringA");
        map2.put("KeyB", "StringB");

        map.put("KeyThree", map2);
        list.add(map);

        List list2 = new ArrayList();
        list2.add("foo");
        list2.add(map);
        list2.add(map);
        list.add(list2);

        context = JXPathContext.newContext(list);

        assertEquals("SomeStringOne", context.getValue(".[1]/KeyOne"));
        assertEquals("StringA", context.getValue(".[1]/KeyThree/KeyA"));
        assertEquals(new Integer(3), 
context.getValue("size(.[1]/KeyThree)"));
        assertEquals(new Double(6.0), 
context.getValue("count(.[1]/KeyThree/*)"));
        assertEquals(new Double(3.0), 
context.getValue("count(.[1]/KeyThree/KeyA)"));
    }

Please let me know if this fixes the problem for you.

Thank you very much for your feedback.

Regards,

- Dmitri


----- Original Message ----- 
From: "Scott Heaberlin" <heabdogg@gmail.com>
To: "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
Sent: Friday, March 18, 2005 10:19 AM
Subject: Re: [JXPATH] StackOverflowError with xpath to Map object


> That structure at first seemed like what I was using (or at least the
> relevant part of the root structure from my JXPathContext).
>
> I ran your test locally and it succeeded.  I ran my test case again
> and it failed, in the same VM with the same classpath.
>
> The only difference in your test and mine is that my test has a second
> element in the outermost List - a list within a list.  Though the
> xpath query that is failing does not reference (or at least, should
> not) that part of the structure I nearly blew it off... but look what
> happens with your very own test case when I add another vector (like
> my own scenario):
>
> public void testCollectionPointer() {
>   List list = new ArrayList();
>
>   Map map = new HashMap();
>   map.put("KeyOne", "SomeStringOne");
>   map.put("KeyTwo", "SomeStringTwo");
>
>   Map map2 = new HashMap();
>   map2.put("KeyA", "StringA");
>   map2.put("KeyB", "StringB");
>
>   map.put("KeyThree", map2);
>
>   list.add(map);
>
>   list.add(new Vector(22));  // <-- NOTE: this is the only difference
>
>   context = JXPathContext.newContext(list);
>
>   System.out.println(context.getValue(".[1]/KeyOne"));
>   System.out.println(context.getValue(".[1]/KeyThree/KeyA"));
>   System.out.println(context.getValue(".[1]/KeyThree"));
>   System.out.println(context.getValue("count(.[1]/KeyThree/*)"));
> }
>
> When running this, I get:
>
> ------------- Standard Output ---------------
> SomeStringOne
> StringA
> {KeyB=StringB, KeyA=StringA}
> ------------- ---------------- ---------------
> Testcase: testCollectionPointer1(test.JXPathTest): Caused an ERROR
> null
> java.lang.StackOverflowError
>
>
> Note: there is no possibility of a circular reference, as that inner
> Vector is size 22 but has all null elements.
>
> Do you get the same result?
>
> Also - I tried the following xpath (calls Map::size) and I get the
> exact same result:
>
> context.getValue("size(.[1]/KeyThree/*)")
>
> Does this happen for you as well?  I had a co-worker verify the
> results in a different development environment (I'm running in
> JDK1.4.2_06, he was using an earlier JDK1.4 release).  We both get a
> stack overflow in the two scenarios (size() and count() )
>
>
> I appreciate the help!
>
> -Scott Heaberlin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
> 



---------------------------------------------------------------------
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