commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Laurent Malvert (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 Tue, 04 Feb 2014 13:20:10 GMT

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

Laurent Malvert commented on JXPATH-164:
----------------------------------------

Thanks for having a look Michele. Your investigation seems correct.


Got some weirder stuff for you, that relates to the other problem I was mentioning...

If you try to change your test's addObject method to

{code}
    private void addObj(List<Object> list, String string) {
        final Map<String, String> map = new HashMap<>();
        map.put("ID", string);
        map.put("VALUE", string);
        list.add(map);
    }
{code}

Then tests still pass fine (as expected).

Then if you do the following, so that one of them contains an empty string:

{code}
    private void addObj(List<Object> list, String string) {
        final Map<String, String> map = new HashMap<>();
        map.put("ID", string);
        map.put("VALUE", (!string.equals("2") ? string : ""));
        list.add(map);
    }
{code}

it still passes fine (as expected).

But if you change it to:

{code}
    private void addObj(List<Object> list, String string) {
        final Map<String, String> map = new HashMap<>();
        map.put("ID", string);
        map.put("COMM", (!string.equals("2") ? string : ""));
        list.add(map);
    }
{code}

Then it breaks on these:

{noformat}
test164_WithRoot: assertEquals(3, jxp.selectNodes("descendant-or-self::node()[*]/ID") .size());
test164_Original: assertEquals(3, jxp.selectNodes("/*/.[*]/ID").size());
test164_Original_Expanded: assertEquals(3, jxp.selectNodes("/.[*]/ID").size());
{noformat}

It's weird as these should not matter for the requested query expression, and because it seems
to fail depending on the key's name (which I obviously assume is a red herring, but might
help to isolate what's going on).


> 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)

Mime
View raw message