You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by joern turner <jo...@web.de> on 2003/12/19 21:00:58 UTC
[jxpath] last() function not working
Hello,
i encountered a problem with the last() function in jxpath.
i've had the problem with recent nightly builds (20031120 and 20031219)
here's the testcase:
Document doc = getXmlResource("instance.xml");
JXPathContext context = JXPathContext.newContext(doc);
Pointer pointer1 = context.getPointer("//my:order/my:item[2]");
assertTrue(pointer1.asPath().equals("/instance[1]/my:order[1]/my:item[2]"));
Pointer pointer2
=context.getPointer("//my:order/my:item[position()=count(../*)]");
assertTrue(pointer2.asPath().equals("/instance[1]/my:order[1]/my:item[2]"));
Pointer pointer3 =
context.getPointer("//my:order/my:item[position()=2]");
assertTrue(pointer3.asPath().equals("/instance[1]/my:order[1]/my:item[2]"));
Pointer pointer4 = context.getPointer("//my:order/my:item[last()]");
assertTrue(pointer4.asPath().equals("/instance[1]/my:order[1]/my:item[2]"));
while the first three assertions pass the fourth fails with the
following stacktrace (sorry for ugly formatting):
testLast(org.chiba.xml.xforms.xpath.test.JXPathTest)java.lang.NullPointerException
at
org.apache.commons.jxpath.ri.model.dom.DOMNodeIterator.previous(DOMNodeIterator.java:131)
at
org.apache.commons.jxpath.ri.model.dom.DOMNodeIterator.setPosition(DOMNodeIterator.java:121)
at
org.apache.commons.jxpath.ri.axes.ChildContext.setPosition(ChildContext.java:152)
at
org.apache.commons.jxpath.ri.compiler.CoreFunction.functionLast(CoreFunction.java:335)
at
org.apache.commons.jxpath.ri.compiler.CoreFunction.computeValue(CoreFunction.java:259)
at
org.apache.commons.jxpath.ri.axes.PredicateContext.nextNode(PredicateContext.java:127)
at
org.apache.commons.jxpath.ri.EvalContext.getSingleNodePointer(EvalContext.java:333)
at org.apache.commons.jxpath.ri.compiler.Path.searchForPath(Path.java:211)
at
org.apache.commons.jxpath.ri.compiler.Path.getSingleNodePointerForSteps(Path.java:192)
at
org.apache.commons.jxpath.ri.compiler.LocationPath.computeValue(LocationPath.java:128)
at
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getPointer(JXPathContextReferenceImpl.java:366)
at
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getPointer(JXPathContextReferenceImpl.java:362)
at org.chiba.xml.xforms.xpath.test.JXPathTest.testLast(JXPathTest.java:162)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at
com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java:12)
i've attached the xml-file used in the test.
Joern