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

Michele Vivoda updated JXPATH-164:
----------------------------------

    Attachment: JXPath164Test.java

Test case

> 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
>         Attachments: JXPath164Test.java
>
>
> 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)

Reply via email to