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


<?xml version="1.0" encoding="iso-8859-1"?>
<instance xmlns:my="test">
  <my:order my:money="4711">
    <my:item my:money="50">
      <my:amount>500</my:amount>
      <my:discount>100</my:discount>
    </my:item>
    <my:item my:money="4711">
      <my:amount>77</my:amount>
      <my:discount>77</my:discount>
    </my:item>
  </my:order>
</instance>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to