commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michele Vivoda (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (JXPATH-164) jxpath returns the wrong number of entries if a map contains an empty string value
Date Mon, 03 Feb 2014 23:09:06 GMT

    [ https://issues.apache.org/jira/browse/JXPATH-164?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13890074#comment-13890074
] 

Michele Vivoda commented on JXPATH-164:
---------------------------------------

Hi,

may be your problem is somehow related to the absence of a 'root' node, since XPath was designed
for XML documents there are some inconsistencies (what is a document?, what is {{/}}) when
used (as does JXPath) with beans. Even more when used directly on collections. I reformulated
your 3-ID(s) test using a root map with the list as a 'field', called ' list ' and it looks
working as expected, however running the tests directly on a -list- as you do, I found out
that any of {{/node() | node() | /\* | \*}} on the three-maps-list context of your example,
returns the first ID value "1" ! So if {{/\*}} is already the ID then {{/\*/ID}} is no match.
This behavior looks strange might possibly need further investigation, not sure also if affects
child collections in tree.. see the attached test. 

My suggestion is to see if using a root map with a root field containing the list fix your
problems

If can be fixed using a root (map), considering there is not a spec of how xpath could work
on collections, I am not sure of what should be done. 


Bye

PS: not related to problem, but I was not sure about {{/.\[*]}} so I tried it in other XPath
engines and Xalan gave me one answer:
bq. {{..\[predicate]}} or {{.\[predicate]}} is illegal syntax.  Use {{self::node()\[predicate]}}

while Saxon, Jaxen and JXPath return 'context/any node if has child elements', like {{self::node()\[*]}}



> jxpath returns the wrong number of entries if a map contains an empty string value
> ----------------------------------------------------------------------------------
>
>                 Key: JXPATH-164
>                 URL: https://issues.apache.org/jira/browse/JXPATH-164
>             Project: Commons JXPath
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4
>            Reporter: Laurent Malvert
>
> It's a bit of an odd one, but I've noticed the following strange behaviors where JXPath
seems to get quite confused when you have an object graph containing maps, where the map contains
some objects with an
> empty string:
> {code}
>         final JXPathContext jxp = JXPathContext.newContext(ImmutableList.<Map<String,
String>>of(
>                 ImmutableMap.of(
>                         "ID", "1",
>                         "STUFF", ""
>                 ),
>                 ImmutableMap.of(
>                         "ID", "2",
>                         "STUFF", "42"
>                 ),
>                 ImmutableMap.of(
>                         "ID", "3",
>                         "STUFF", ""
>                 )
>         ));
>         assertEquals(3, jxp.selectNodes("ID").size());
>         assertEquals(3, jxp.selectNodes("//ID").size());
>         assertEquals(3, jxp.selectNodes("/ID").size());
>         assertEquals(3, jxp.selectNodes("/.[*]/ID").size());
>         assertEquals(1, jxp.selectNodes("/*/ID").size()); // SHOULD RETURN 3
> {code}
> Now, if you runt the same test with this:
> {code}
>         final JXPathContext jxp = JXPathContext.newContext(ImmutableList.<Map<String,
String>>of(
>                 ImmutableMap.of(
>                         "ID", "1"
>                 ),
>                 ImmutableMap.of(
>                         "ID", "2"
>                 ),
>                 ImmutableMap.of(
>                         "ID", "3"
>                 )
>         ));
>         assertEquals(3, jxp.selectNodes("ID").size());
>         assertEquals(3, jxp.selectNodes("//ID").size());
>         assertEquals(3, jxp.selectNodes("/ID").size());
>         assertEquals(3, jxp.selectNodes("/.[*]/ID").size());
>         assertEquals(0, jxp.selectNodes("/*/ID").size()); // should return 3
> {code}
> Notice how that last result is a 0, whereas we got a one in the first test, though the
logical structure of the contextbean is the same.
> And now for added fun... The odder thing is that I get slightly different behaviors for
other seemingly simple datasets.
> For instance, consider this data set converted to an object graph:
> {noformat}
> [ {
>   "EMPNO" : "7369",
>   "ENAME" : "SMITH",
>   "JOB" : "test",
>   "MGR" : "7902",
>   "HIREDATE" : "Wed Dec 17 05:00:00 GMT 1980",
>   "SAL" : "800.0",
>   "COMM" : "",
>   "DEPTNO" : "20"
> }, {
>   "EMPNO" : "7499",
>   "ENAME" : "ALLEN",
>   "JOB" : "SALESMAN",
>   "MGR" : "7698",
>   "HIREDATE" : "Fri Feb 20 05:00:00 GMT 1981",
>   "SAL" : "1600.0",
>   "COMM" : "300.0",
>   "DEPTNO" : "30"
> }, {
>   "EMPNO" : "7521",
>   "ENAME" : "WARD",
>   "JOB" : "SALESMAN",
>   "MGR" : "7698",
>   "HIREDATE" : "Sun Feb 22 05:00:00 GMT 1981",
>   "SAL" : "1250.0",
>   "COMM" : "500.0",
>   "DEPTNO" : "30"
> }, {
>   "EMPNO" : "7566",
>   "ENAME" : "JONES",
>   "JOB" : "MANAGER",
>   "MGR" : "7839",
>   "HIREDATE" : "Thu Apr 02 06:00:00 BST 1981",
>   "SAL" : "2975.0",
>   "COMM" : "",
>   "DEPTNO" : "20"
> }, {
>   "EMPNO" : "7654",
>   "ENAME" : "MARTIN",
>   "JOB" : "SALESMAN",
>   "MGR" : "7698",
>   "HIREDATE" : "Mon Sep 28 05:00:00 BST 1981",
>   "SAL" : "1250.0",
>   "COMM" : "1400.0",
>   "DEPTNO" : "30"
> }, {
>   "EMPNO" : "7698",
>   "ENAME" : "BLAKE",
>   "JOB" : "MANAGER",
>   "MGR" : "7839",
>   "HIREDATE" : "Fri May 01 05:00:00 BST 1981",
>   "SAL" : "2850.0",
>   "COMM" : "",
>   "DEPTNO" : "30"
> }, {
>   "EMPNO" : "7782",
>   "ENAME" : "CLARK",
>   "JOB" : "MANAGER",
>   "MGR" : "7839",
>   "HIREDATE" : "Tue Jun 09 05:00:00 BST 1981",
>   "SAL" : "2450.0",
>   "COMM" : "",
>   "DEPTNO" : "10"
> }, {
>   "EMPNO" : "7788",
>   "ENAME" : "SCOTT",
>   "JOB" : "ANALYST",
>   "MGR" : "7566",
>   "HIREDATE" : "Sun Apr 19 05:00:00 BST 1987",
>   "SAL" : "3000.0",
>   "COMM" : "",
>   "DEPTNO" : "20"
> }, {
>   "EMPNO" : "7839",
>   "ENAME" : "KING",
>   "JOB" : "PRESIDENT",
>   "MGR" : "",
>   "HIREDATE" : "Tue Nov 17 05:00:00 GMT 1981",
>   "SAL" : "5000.0",
>   "COMM" : "",
>   "DEPTNO" : "10"
> }, {
>   "EMPNO" : "7844",
>   "ENAME" : "TURNER",
>   "JOB" : "SALESMAN",
>   "MGR" : "7698",
>   "HIREDATE" : "Tue Sep 08 05:00:00 BST 1981",
>   "SAL" : "1500.0",
>   "COMM" : "0.0",
>   "DEPTNO" : "30"
> }, {
>   "EMPNO" : "7876",
>   "ENAME" : "ADAMS",
>   "JOB" : "CLERK",
>   "MGR" : "7788",
>   "HIREDATE" : "Sat May 23 05:00:00 BST 1987",
>   "SAL" : "1100.0",
>   "COMM" : "",
>   "DEPTNO" : "20"
> }, {
>   "EMPNO" : "7900",
>   "ENAME" : "JAMES",
>   "JOB" : "CLERK",
>   "MGR" : "7698",
>   "HIREDATE" : "Thu Dec 03 05:00:00 GMT 1981",
>   "SAL" : "950.0",
>   "COMM" : "",
>   "DEPTNO" : "30"
> }, {
>   "EMPNO" : "7902",
>   "ENAME" : "FORD",
>   "JOB" : "ANALYST",
>   "MGR" : "7566",
>   "HIREDATE" : "Thu Dec 03 05:00:00 GMT 1981",
>   "SAL" : "3000.0",
>   "COMM" : "",
>   "DEPTNO" : "20"
> }, {
>   "EMPNO" : "7934",
>   "ENAME" : "MILLER",
>   "JOB" : "CLERK",
>   "MGR" : "7782",
>   "HIREDATE" : "Sat Jan 23 05:00:00 GMT 1982",
>   "SAL" : "1300.0",
>   "COMM" : "",
>   "DEPTNO" : "10"
> } ]
> {noformat}
> {code}
>         final JXPathContext jxp = JXPathContext.newContext(employeeList);
>         assertEquals(14, jxp.selectNodes("EMPNO").size());
>         assertEquals(14, jxp.selectNodes("//EMPNO").size());
>         assertEquals(4, jxp.selectNodes("/.[*]/EMPNO").size()); // should be 14
>         assertEquals(14, jxp.selectNodes("/EMPNO").size());
>         assertEquals(0, jxp.selectNodes("/*/EMPNO").size()); // should also be 14
> {code}
> Here we notice that the last result is wrong again as well... but the index based one
is wrong as well. And it seems like it's only returning entries where all map values where
non-empty.
> Not sure if there's something I'm not getting, but it looks like something isn't quite
right here.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Mime
View raw message