[ 
https://issues.apache.org/jira/browse/JXPATH-139?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Matt Benson resolved JXPATH-139.
--------------------------------

    Resolution: Invalid

Hello, and sorry for the long wait.  I have looked at this before, but have 
finally realized that this issue is invalid.  You must bear in mind that this 
is xpath, so when you pass a path to a function, you are really passing the set 
of nodes that matches that query, in this case "those nodes relative to the 
current path (root) whose qname matches 'valueXXX'."  This empty nodeset is 
then converted to a string, yielding the value "".  Unfortunately this does 
mean that your jxpath expressions will not automatically break when 
refactorings change property names.
                
> 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.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to