Wrong xpath expression passed to extension function does not throw
JXPathNotFoundException
------------------------------------------------------------------------------------------
Key: JXPATH-139
URL: https://issues.apache.org/jira/browse/JXPATH-139
Project: Commons JXPath
Issue Type: Bug
Affects Versions: 1.3
Reporter: Petras
If xpath expression, which do not map to bean properties, is passed to
extension function, JXPathNotFoundException is not thrown. It seems
inconsistent behaviour and it is difficult to test these expressions if they do
not fail for example after code refactoring.
Here is a test case:
{code}
// Extension function
public static class StringFunctions {
public static String left(String param, int len) {
System.out.println("Received: '" + param + "'");
if(param == null) return null;
return param.substring(0, Math.min(len, param.length()));
}
}
{code}
{code}
// Value object to use
public class VO {
String value = null;
public String getValue() { return value; }
public void setValue(String value) { this.value = value; }
}
{code}
{code}
@Test
public void testLeftFunctionWrongPath() {
VO vo = new VO();
vo.setValue("1234567890");
JXPathContext ctx = JXPathContext.newContext(vo);
ctx.setFunctions(new ClassFunctions(StringFunctions.class, "util"));
// OK, StringFunctions.left() receives "1234567890"
path = "util:left(value, 5)";
ctx.getValue(path);
// JXPathNotFoundException is not thrown, StringFunctions.left()
receives an empty string
String wrongPath = "util:left(valueXXX, 5)";
ctx.getValue(wrongPath);
}
{code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.