You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "John Attwood (JIRA)" <ji...@apache.org> on 2006/10/09 15:57:19 UTC
[jira] Created: (JXPATH-71) Ponter.asPath() return values not
always correct
Ponter.asPath() return values not always correct
------------------------------------------------
Key: JXPATH-71
URL: http://issues.apache.org/jira/browse/JXPATH-71
Project: Commons JXPath
Issue Type: Bug
Affects Versions: 1.2 Final
Environment: WInXP, Java 1.5, Eclipse 3.2
Reporter: John Attwood
String returned by Pointer.asPath() is incorrect when path starts with '//' and target is a collection. The path returned always has a final subscript equal to the size of the collection, although Pointer.getValue() still returns the correct element in each case. Below are two classes and a JUnit testcase which reproduce the bug and isolate it to the case where the path starts with '//' and the target is a collection.
I found this problem whilst trying to write the equivalent of XPathExplorer for my JXPath-based object trees. It does't affect the main app, as getValue() always returns the correct node, but in my explorer it only ever highlights the last element in any collection (the objects in my trees aren't always unique so the path is only way to identify them individually and allow the matching nodes to be highlighted).
Otherwise an excellent, easy-to-use and really useful package.
/////////////////////////////////////// Parent.java //////////////////////////////////////////////////////////////////////////////////
package test;
import java.util.ArrayList;
public class Parent {
private int id;
private ArrayList<Child> kids;
public Parent(int id) {
this.id = id;
this.kids = new ArrayList<Child>();
}
public int getId() {
return id;
}
public ArrayList<Child> getKids() {
return kids;
}
public void addKid(Child kid) {
kids.add(kid);
}
public void setId(int id) {
this.id = id;
}
public void setKids(ArrayList<Child> kids) {
this.kids = kids;
}
}
/////////////////////////////////////////////////////////// Child.java /////////////////////////////////////////////////////////////////////////////////////////////////////////////
package test;
public class Child {
private int id;
public Child(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
/////////////////////////////////////////////////////////// TestPointerToPath.java ///////////////////////////////////////////////////////////////////////////
package test;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import junit.framework.TestCase;
import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.Pointer;
public class TestPonterToPath extends TestCase {
private Parent parent;
private Set<String> expectedPaths, actualPaths;
private Set<Object> actualObjects, expectedObjects;
private JXPathContext ctx;
private static final int SIZE = 4;
public void setUp() {
parent = new Parent(1);
for (int i = 1; i <= SIZE; i++) {
parent.addKid(new Child(i));
}
expectedPaths = new HashSet<String>();
expectedObjects = new HashSet<Object>();
actualPaths = new HashSet<String>();
actualObjects = new HashSet<Object>();
ctx = JXPathContext.newContext(parent);
}
private void doExpected(String path1, String path2) {
for (int i = 1; i <= SIZE; i++) {
Pointer p = ctx.getPointer(path1 + i + path2);
expectedPaths.add(p.asPath());
expectedObjects.add(p.getValue());
}
assertEquals(SIZE, expectedPaths.size());
assertEquals(SIZE, expectedObjects.size());
}
private void doActual(String path) {
Iterator it = ctx.iteratePointers(path);
while (it.hasNext()) {
Pointer p = (Pointer) it.next();
actualPaths.add(p.asPath());
actualObjects.add(p.getValue());
}
assertEquals(SIZE, actualObjects.size());
}
public void testToPathLeafAbs() {
doExpected("/kids[", "]/id");
doActual("/kids/id");
assertEquals(expectedObjects, actualObjects);
assertEquals(expectedPaths, actualPaths);
}
public void testToPathLeafRel() {
doExpected("//kids[", "]/id");
doActual("//kids/id");
assertEquals(expectedObjects, actualObjects);
assertEquals(expectedPaths, actualPaths);
}
public void testToPathCollectionAbs() {
doExpected("/kids[", "]");
doActual("/kids");
assertEquals(expectedObjects, actualObjects);
assertEquals(expectedPaths, actualPaths);
}
public void testToPathCollectionRel() {
doExpected("//kids[", "]");
doActual("//kids");
assertEquals(expectedObjects, actualObjects);
/* next test fails as all actualPaths are /kids[SIZE] */
assertEquals(expectedPaths, actualPaths);
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [jira] Created: (JXPATH-71) Ponter.asPath() return values not always correct
Posted by Dmitri Plotnikov <dm...@apache.org>.
John,
A similar bug was reported and fixed a long time ago. Are you sure this is
still an issue with the current build of JXPath?
Thank you,
- Dmitri
----- Original Message -----
From: "John Attwood (JIRA)" <ji...@apache.org>
To: <co...@jakarta.apache.org>
Sent: Monday, October 09, 2006 9:57 AM
Subject: [jira] Created: (JXPATH-71) Ponter.asPath() return values not
always correct
> Ponter.asPath() return values not always correct
> ------------------------------------------------
>
> Key: JXPATH-71
> URL: http://issues.apache.org/jira/browse/JXPATH-71
> Project: Commons JXPath
> Issue Type: Bug
> Affects Versions: 1.2 Final
> Environment: WInXP, Java 1.5, Eclipse 3.2
> Reporter: John Attwood
>
>
> String returned by Pointer.asPath() is incorrect when path starts with
> '//' and target is a collection. The path returned always has a final
> subscript equal to the size of the collection, although Pointer.getValue()
> still returns the correct element in each case. Below are two classes and
> a JUnit testcase which reproduce the bug and isolate it to the case where
> the path starts with '//' and the target is a collection.
>
> I found this problem whilst trying to write the equivalent of
> XPathExplorer for my JXPath-based object trees. It does't affect the main
> app, as getValue() always returns the correct node, but in my explorer it
> only ever highlights the last element in any collection (the objects in my
> trees aren't always unique so the path is only way to identify them
> individually and allow the matching nodes to be highlighted).
>
> Otherwise an excellent, easy-to-use and really useful package.
>
> /////////////////////////////////////// Parent.java
> //////////////////////////////////////////////////////////////////////////////////
> package test;
>
> import java.util.ArrayList;
>
> public class Parent {
> private int id;
>
> private ArrayList<Child> kids;
>
> public Parent(int id) {
> this.id = id;
> this.kids = new ArrayList<Child>();
> }
>
> public int getId() {
> return id;
> }
>
> public ArrayList<Child> getKids() {
> return kids;
> }
>
> public void addKid(Child kid) {
> kids.add(kid);
> }
>
> public void setId(int id) {
> this.id = id;
> }
>
> public void setKids(ArrayList<Child> kids) {
> this.kids = kids;
> }
> }
>
> /////////////////////////////////////////////////////////// Child.java
> /////////////////////////////////////////////////////////////////////////////////////////////////////////////
> package test;
>
> public class Child {
> private int id;
>
> public Child(int id) {
> this.id = id;
> }
>
> public int getId() {
> return id;
> }
>
> public void setId(int id) {
> this.id = id;
> }
> }
>
> ///////////////////////////////////////////////////////////
> TestPointerToPath.java
> ///////////////////////////////////////////////////////////////////////////
> package test;
>
> import java.util.HashSet;
> import java.util.Iterator;
> import java.util.Set;
>
> import junit.framework.TestCase;
>
> import org.apache.commons.jxpath.JXPathContext;
> import org.apache.commons.jxpath.Pointer;
>
> public class TestPonterToPath extends TestCase {
> private Parent parent;
> private Set<String> expectedPaths, actualPaths;
> private Set<Object> actualObjects, expectedObjects;
> private JXPathContext ctx;
>
> private static final int SIZE = 4;
>
> public void setUp() {
> parent = new Parent(1);
> for (int i = 1; i <= SIZE; i++) {
> parent.addKid(new Child(i));
> }
> expectedPaths = new HashSet<String>();
> expectedObjects = new HashSet<Object>();
> actualPaths = new HashSet<String>();
> actualObjects = new HashSet<Object>();
> ctx = JXPathContext.newContext(parent);
> }
>
> private void doExpected(String path1, String path2) {
> for (int i = 1; i <= SIZE; i++) {
> Pointer p = ctx.getPointer(path1 + i + path2);
> expectedPaths.add(p.asPath());
> expectedObjects.add(p.getValue());
> }
> assertEquals(SIZE, expectedPaths.size());
> assertEquals(SIZE, expectedObjects.size());
> }
>
> private void doActual(String path) {
> Iterator it = ctx.iteratePointers(path);
> while (it.hasNext()) {
> Pointer p = (Pointer) it.next();
> actualPaths.add(p.asPath());
> actualObjects.add(p.getValue());
> }
> assertEquals(SIZE, actualObjects.size());
> }
>
> public void testToPathLeafAbs() {
> doExpected("/kids[", "]/id");
> doActual("/kids/id");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
>
> public void testToPathLeafRel() {
> doExpected("//kids[", "]/id");
> doActual("//kids/id");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
>
> public void testToPathCollectionAbs() {
> doExpected("/kids[", "]");
> doActual("/kids");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
>
> public void testToPathCollectionRel() {
> doExpected("//kids[", "]");
> doActual("//kids");
> assertEquals(expectedObjects, actualObjects);
> /* next test fails as all actualPaths are /kids[SIZE] */
> assertEquals(expectedPaths, actualPaths);
> }
>
> }
>
>
>
> --
> This message is automatically generated by JIRA.
> -
> If you think it was sent incorrectly contact one of the administrators:
> http://issues.apache.org/jira/secure/Administrators.jspa
> -
> For more information on JIRA, see: http://www.atlassian.com/software/jira
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
[jira] Commented: (JXPATH-71) Ponter.asPath() return values not
always correct
Posted by "John Attwood (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JXPATH-71?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12462169 ]
John Attwood commented on JXPATH-71:
------------------------------------
Hi,
Thanks for looking into this. I've rerun my tests against the latest
build and they all pass.
However, the current stable release still appears to be 1.2 final, which
is the one that contains the bug. I'm not sure that I'd be allowed to
use a nightly build with production code, so when do you think we can
expect v1.3 to be released?
Thanks,
John.
https://issues.apache.org/jira/browse/JXPATH-71?page=com.atlassian.jira.plugin.s
ystem.issuetabpanels:comment-tabpanel#action_12462092 ]
and target is a collection. The path returned always has a final subscript equal
to the size of the collection, although Pointer.getValue() still returns the
correct element in each case. Below are two classes and a JUnit testcase which
reproduce the bug and isolate it to the case where the path starts with '//' and
the target is a collection.
for my JXPath-based object trees. It does't affect the main app, as getValue()
always returns the correct node, but in my explorer it only ever highlights the
last element in any collection (the objects in my trees aren't always unique so
the path is only way to identify them individually and allow the matching nodes
to be highlighted).
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////
TestPointerToPath.java
///////////////////////////////////////////////////////////////////////////
https://issues.apache.org/jira/secure/Administrators.jspa
> Ponter.asPath() return values not always correct
> ------------------------------------------------
>
> Key: JXPATH-71
> URL: https://issues.apache.org/jira/browse/JXPATH-71
> Project: Commons JXPath
> Issue Type: Bug
> Affects Versions: 1.2 Final
> Environment: WInXP, Java 1.5, Eclipse 3.2
> Reporter: John Attwood
>
> String returned by Pointer.asPath() is incorrect when path starts with '//' and target is a collection. The path returned always has a final subscript equal to the size of the collection, although Pointer.getValue() still returns the correct element in each case. Below are two classes and a JUnit testcase which reproduce the bug and isolate it to the case where the path starts with '//' and the target is a collection.
> I found this problem whilst trying to write the equivalent of XPathExplorer for my JXPath-based object trees. It does't affect the main app, as getValue() always returns the correct node, but in my explorer it only ever highlights the last element in any collection (the objects in my trees aren't always unique so the path is only way to identify them individually and allow the matching nodes to be highlighted).
> Otherwise an excellent, easy-to-use and really useful package.
> /////////////////////////////////////// Parent.java //////////////////////////////////////////////////////////////////////////////////
> package test;
> import java.util.ArrayList;
> public class Parent {
> private int id;
> private ArrayList<Child> kids;
> public Parent(int id) {
> this.id = id;
> this.kids = new ArrayList<Child>();
> }
> public int getId() {
> return id;
> }
> public ArrayList<Child> getKids() {
> return kids;
> }
> public void addKid(Child kid) {
> kids.add(kid);
> }
> public void setId(int id) {
> this.id = id;
> }
> public void setKids(ArrayList<Child> kids) {
> this.kids = kids;
> }
> }
> /////////////////////////////////////////////////////////// Child.java /////////////////////////////////////////////////////////////////////////////////////////////////////////////
> package test;
> public class Child {
> private int id;
> public Child(int id) {
> this.id = id;
> }
> public int getId() {
> return id;
> }
> public void setId(int id) {
> this.id = id;
> }
> }
> /////////////////////////////////////////////////////////// TestPointerToPath.java ///////////////////////////////////////////////////////////////////////////
> package test;
> import java.util.HashSet;
> import java.util.Iterator;
> import java.util.Set;
> import junit.framework.TestCase;
> import org.apache.commons.jxpath.JXPathContext;
> import org.apache.commons.jxpath.Pointer;
> public class TestPonterToPath extends TestCase {
> private Parent parent;
> private Set<String> expectedPaths, actualPaths;
> private Set<Object> actualObjects, expectedObjects;
> private JXPathContext ctx;
>
> private static final int SIZE = 4;
>
> public void setUp() {
> parent = new Parent(1);
> for (int i = 1; i <= SIZE; i++) {
> parent.addKid(new Child(i));
> }
> expectedPaths = new HashSet<String>();
> expectedObjects = new HashSet<Object>();
> actualPaths = new HashSet<String>();
> actualObjects = new HashSet<Object>();
> ctx = JXPathContext.newContext(parent);
> }
>
> private void doExpected(String path1, String path2) {
> for (int i = 1; i <= SIZE; i++) {
> Pointer p = ctx.getPointer(path1 + i + path2);
> expectedPaths.add(p.asPath());
> expectedObjects.add(p.getValue());
> }
> assertEquals(SIZE, expectedPaths.size());
> assertEquals(SIZE, expectedObjects.size());
> }
>
> private void doActual(String path) {
> Iterator it = ctx.iteratePointers(path);
> while (it.hasNext()) {
> Pointer p = (Pointer) it.next();
> actualPaths.add(p.asPath());
> actualObjects.add(p.getValue());
> }
> assertEquals(SIZE, actualObjects.size());
> }
> public void testToPathLeafAbs() {
> doExpected("/kids[", "]/id");
> doActual("/kids/id");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
> public void testToPathLeafRel() {
> doExpected("//kids[", "]/id");
> doActual("//kids/id");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
> public void testToPathCollectionAbs() {
> doExpected("/kids[", "]");
> doActual("/kids");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
>
> public void testToPathCollectionRel() {
> doExpected("//kids[", "]");
> doActual("//kids");
> assertEquals(expectedObjects, actualObjects);
> /* next test fails as all actualPaths are /kids[SIZE] */
> assertEquals(expectedPaths, actualPaths);
> }
>
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
[jira] Commented: (JXPATH-71) Ponter.asPath() return values not
always correct
Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JXPATH-71?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12462498 ]
Matt Benson commented on JXPATH-71:
-----------------------------------
Grrr, make that JXPATH-5 . Sorry!
> Ponter.asPath() return values not always correct
> ------------------------------------------------
>
> Key: JXPATH-71
> URL: https://issues.apache.org/jira/browse/JXPATH-71
> Project: Commons JXPath
> Issue Type: Bug
> Affects Versions: 1.2 Final
> Environment: WInXP, Java 1.5, Eclipse 3.2
> Reporter: John Attwood
>
> String returned by Pointer.asPath() is incorrect when path starts with '//' and target is a collection. The path returned always has a final subscript equal to the size of the collection, although Pointer.getValue() still returns the correct element in each case. Below are two classes and a JUnit testcase which reproduce the bug and isolate it to the case where the path starts with '//' and the target is a collection.
> I found this problem whilst trying to write the equivalent of XPathExplorer for my JXPath-based object trees. It does't affect the main app, as getValue() always returns the correct node, but in my explorer it only ever highlights the last element in any collection (the objects in my trees aren't always unique so the path is only way to identify them individually and allow the matching nodes to be highlighted).
> Otherwise an excellent, easy-to-use and really useful package.
> /////////////////////////////////////// Parent.java //////////////////////////////////////////////////////////////////////////////////
> package test;
> import java.util.ArrayList;
> public class Parent {
> private int id;
> private ArrayList<Child> kids;
> public Parent(int id) {
> this.id = id;
> this.kids = new ArrayList<Child>();
> }
> public int getId() {
> return id;
> }
> public ArrayList<Child> getKids() {
> return kids;
> }
> public void addKid(Child kid) {
> kids.add(kid);
> }
> public void setId(int id) {
> this.id = id;
> }
> public void setKids(ArrayList<Child> kids) {
> this.kids = kids;
> }
> }
> /////////////////////////////////////////////////////////// Child.java /////////////////////////////////////////////////////////////////////////////////////////////////////////////
> package test;
> public class Child {
> private int id;
> public Child(int id) {
> this.id = id;
> }
> public int getId() {
> return id;
> }
> public void setId(int id) {
> this.id = id;
> }
> }
> /////////////////////////////////////////////////////////// TestPointerToPath.java ///////////////////////////////////////////////////////////////////////////
> package test;
> import java.util.HashSet;
> import java.util.Iterator;
> import java.util.Set;
> import junit.framework.TestCase;
> import org.apache.commons.jxpath.JXPathContext;
> import org.apache.commons.jxpath.Pointer;
> public class TestPonterToPath extends TestCase {
> private Parent parent;
> private Set<String> expectedPaths, actualPaths;
> private Set<Object> actualObjects, expectedObjects;
> private JXPathContext ctx;
>
> private static final int SIZE = 4;
>
> public void setUp() {
> parent = new Parent(1);
> for (int i = 1; i <= SIZE; i++) {
> parent.addKid(new Child(i));
> }
> expectedPaths = new HashSet<String>();
> expectedObjects = new HashSet<Object>();
> actualPaths = new HashSet<String>();
> actualObjects = new HashSet<Object>();
> ctx = JXPathContext.newContext(parent);
> }
>
> private void doExpected(String path1, String path2) {
> for (int i = 1; i <= SIZE; i++) {
> Pointer p = ctx.getPointer(path1 + i + path2);
> expectedPaths.add(p.asPath());
> expectedObjects.add(p.getValue());
> }
> assertEquals(SIZE, expectedPaths.size());
> assertEquals(SIZE, expectedObjects.size());
> }
>
> private void doActual(String path) {
> Iterator it = ctx.iteratePointers(path);
> while (it.hasNext()) {
> Pointer p = (Pointer) it.next();
> actualPaths.add(p.asPath());
> actualObjects.add(p.getValue());
> }
> assertEquals(SIZE, actualObjects.size());
> }
> public void testToPathLeafAbs() {
> doExpected("/kids[", "]/id");
> doActual("/kids/id");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
> public void testToPathLeafRel() {
> doExpected("//kids[", "]/id");
> doActual("//kids/id");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
> public void testToPathCollectionAbs() {
> doExpected("/kids[", "]");
> doActual("/kids");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
>
> public void testToPathCollectionRel() {
> doExpected("//kids[", "]");
> doActual("//kids");
> assertEquals(expectedObjects, actualObjects);
> /* next test fails as all actualPaths are /kids[SIZE] */
> assertEquals(expectedPaths, actualPaths);
> }
>
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
[jira] Commented: (JXPATH-71) Ponter.asPath() return values not
always correct
Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JXPATH-71?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12462496 ]
Matt Benson commented on JXPATH-71:
-----------------------------------
I think this is a duplicate of JXPATH-71
> Ponter.asPath() return values not always correct
> ------------------------------------------------
>
> Key: JXPATH-71
> URL: https://issues.apache.org/jira/browse/JXPATH-71
> Project: Commons JXPath
> Issue Type: Bug
> Affects Versions: 1.2 Final
> Environment: WInXP, Java 1.5, Eclipse 3.2
> Reporter: John Attwood
>
> String returned by Pointer.asPath() is incorrect when path starts with '//' and target is a collection. The path returned always has a final subscript equal to the size of the collection, although Pointer.getValue() still returns the correct element in each case. Below are two classes and a JUnit testcase which reproduce the bug and isolate it to the case where the path starts with '//' and the target is a collection.
> I found this problem whilst trying to write the equivalent of XPathExplorer for my JXPath-based object trees. It does't affect the main app, as getValue() always returns the correct node, but in my explorer it only ever highlights the last element in any collection (the objects in my trees aren't always unique so the path is only way to identify them individually and allow the matching nodes to be highlighted).
> Otherwise an excellent, easy-to-use and really useful package.
> /////////////////////////////////////// Parent.java //////////////////////////////////////////////////////////////////////////////////
> package test;
> import java.util.ArrayList;
> public class Parent {
> private int id;
> private ArrayList<Child> kids;
> public Parent(int id) {
> this.id = id;
> this.kids = new ArrayList<Child>();
> }
> public int getId() {
> return id;
> }
> public ArrayList<Child> getKids() {
> return kids;
> }
> public void addKid(Child kid) {
> kids.add(kid);
> }
> public void setId(int id) {
> this.id = id;
> }
> public void setKids(ArrayList<Child> kids) {
> this.kids = kids;
> }
> }
> /////////////////////////////////////////////////////////// Child.java /////////////////////////////////////////////////////////////////////////////////////////////////////////////
> package test;
> public class Child {
> private int id;
> public Child(int id) {
> this.id = id;
> }
> public int getId() {
> return id;
> }
> public void setId(int id) {
> this.id = id;
> }
> }
> /////////////////////////////////////////////////////////// TestPointerToPath.java ///////////////////////////////////////////////////////////////////////////
> package test;
> import java.util.HashSet;
> import java.util.Iterator;
> import java.util.Set;
> import junit.framework.TestCase;
> import org.apache.commons.jxpath.JXPathContext;
> import org.apache.commons.jxpath.Pointer;
> public class TestPonterToPath extends TestCase {
> private Parent parent;
> private Set<String> expectedPaths, actualPaths;
> private Set<Object> actualObjects, expectedObjects;
> private JXPathContext ctx;
>
> private static final int SIZE = 4;
>
> public void setUp() {
> parent = new Parent(1);
> for (int i = 1; i <= SIZE; i++) {
> parent.addKid(new Child(i));
> }
> expectedPaths = new HashSet<String>();
> expectedObjects = new HashSet<Object>();
> actualPaths = new HashSet<String>();
> actualObjects = new HashSet<Object>();
> ctx = JXPathContext.newContext(parent);
> }
>
> private void doExpected(String path1, String path2) {
> for (int i = 1; i <= SIZE; i++) {
> Pointer p = ctx.getPointer(path1 + i + path2);
> expectedPaths.add(p.asPath());
> expectedObjects.add(p.getValue());
> }
> assertEquals(SIZE, expectedPaths.size());
> assertEquals(SIZE, expectedObjects.size());
> }
>
> private void doActual(String path) {
> Iterator it = ctx.iteratePointers(path);
> while (it.hasNext()) {
> Pointer p = (Pointer) it.next();
> actualPaths.add(p.asPath());
> actualObjects.add(p.getValue());
> }
> assertEquals(SIZE, actualObjects.size());
> }
> public void testToPathLeafAbs() {
> doExpected("/kids[", "]/id");
> doActual("/kids/id");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
> public void testToPathLeafRel() {
> doExpected("//kids[", "]/id");
> doActual("//kids/id");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
> public void testToPathCollectionAbs() {
> doExpected("/kids[", "]");
> doActual("/kids");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
>
> public void testToPathCollectionRel() {
> doExpected("//kids[", "]");
> doActual("//kids");
> assertEquals(expectedObjects, actualObjects);
> /* next test fails as all actualPaths are /kids[SIZE] */
> assertEquals(expectedPaths, actualPaths);
> }
>
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
[jira] Commented: (JXPATH-71) Ponter.asPath() return values not
always correct
Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JXPATH-71?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12462092 ]
Matt Benson commented on JXPATH-71:
-----------------------------------
On the commons-dev mailing list, Dmitri responded:
John,
A similar bug was reported and fixed a long time ago. Are you sure this is
still an issue with the current build of JXPath?
Thank you,
- Dmitri
see http://marc.theaimsgroup.com/?l=jakarta-commons-dev&m=116048423025988&w=2
> Ponter.asPath() return values not always correct
> ------------------------------------------------
>
> Key: JXPATH-71
> URL: https://issues.apache.org/jira/browse/JXPATH-71
> Project: Commons JXPath
> Issue Type: Bug
> Affects Versions: 1.2 Final
> Environment: WInXP, Java 1.5, Eclipse 3.2
> Reporter: John Attwood
>
> String returned by Pointer.asPath() is incorrect when path starts with '//' and target is a collection. The path returned always has a final subscript equal to the size of the collection, although Pointer.getValue() still returns the correct element in each case. Below are two classes and a JUnit testcase which reproduce the bug and isolate it to the case where the path starts with '//' and the target is a collection.
> I found this problem whilst trying to write the equivalent of XPathExplorer for my JXPath-based object trees. It does't affect the main app, as getValue() always returns the correct node, but in my explorer it only ever highlights the last element in any collection (the objects in my trees aren't always unique so the path is only way to identify them individually and allow the matching nodes to be highlighted).
> Otherwise an excellent, easy-to-use and really useful package.
> /////////////////////////////////////// Parent.java //////////////////////////////////////////////////////////////////////////////////
> package test;
> import java.util.ArrayList;
> public class Parent {
> private int id;
> private ArrayList<Child> kids;
> public Parent(int id) {
> this.id = id;
> this.kids = new ArrayList<Child>();
> }
> public int getId() {
> return id;
> }
> public ArrayList<Child> getKids() {
> return kids;
> }
> public void addKid(Child kid) {
> kids.add(kid);
> }
> public void setId(int id) {
> this.id = id;
> }
> public void setKids(ArrayList<Child> kids) {
> this.kids = kids;
> }
> }
> /////////////////////////////////////////////////////////// Child.java /////////////////////////////////////////////////////////////////////////////////////////////////////////////
> package test;
> public class Child {
> private int id;
> public Child(int id) {
> this.id = id;
> }
> public int getId() {
> return id;
> }
> public void setId(int id) {
> this.id = id;
> }
> }
> /////////////////////////////////////////////////////////// TestPointerToPath.java ///////////////////////////////////////////////////////////////////////////
> package test;
> import java.util.HashSet;
> import java.util.Iterator;
> import java.util.Set;
> import junit.framework.TestCase;
> import org.apache.commons.jxpath.JXPathContext;
> import org.apache.commons.jxpath.Pointer;
> public class TestPonterToPath extends TestCase {
> private Parent parent;
> private Set<String> expectedPaths, actualPaths;
> private Set<Object> actualObjects, expectedObjects;
> private JXPathContext ctx;
>
> private static final int SIZE = 4;
>
> public void setUp() {
> parent = new Parent(1);
> for (int i = 1; i <= SIZE; i++) {
> parent.addKid(new Child(i));
> }
> expectedPaths = new HashSet<String>();
> expectedObjects = new HashSet<Object>();
> actualPaths = new HashSet<String>();
> actualObjects = new HashSet<Object>();
> ctx = JXPathContext.newContext(parent);
> }
>
> private void doExpected(String path1, String path2) {
> for (int i = 1; i <= SIZE; i++) {
> Pointer p = ctx.getPointer(path1 + i + path2);
> expectedPaths.add(p.asPath());
> expectedObjects.add(p.getValue());
> }
> assertEquals(SIZE, expectedPaths.size());
> assertEquals(SIZE, expectedObjects.size());
> }
>
> private void doActual(String path) {
> Iterator it = ctx.iteratePointers(path);
> while (it.hasNext()) {
> Pointer p = (Pointer) it.next();
> actualPaths.add(p.asPath());
> actualObjects.add(p.getValue());
> }
> assertEquals(SIZE, actualObjects.size());
> }
> public void testToPathLeafAbs() {
> doExpected("/kids[", "]/id");
> doActual("/kids/id");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
> public void testToPathLeafRel() {
> doExpected("//kids[", "]/id");
> doActual("//kids/id");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
> public void testToPathCollectionAbs() {
> doExpected("/kids[", "]");
> doActual("/kids");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
>
> public void testToPathCollectionRel() {
> doExpected("//kids[", "]");
> doActual("//kids");
> assertEquals(expectedObjects, actualObjects);
> /* next test fails as all actualPaths are /kids[SIZE] */
> assertEquals(expectedPaths, actualPaths);
> }
>
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
[jira] Resolved: (JXPATH-71) Ponter.asPath() return values not
always correct
Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JXPATH-71?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Niall Pemberton resolved JXPATH-71.
-----------------------------------
Resolution: Duplicate
> Ponter.asPath() return values not always correct
> ------------------------------------------------
>
> Key: JXPATH-71
> URL: https://issues.apache.org/jira/browse/JXPATH-71
> Project: Commons JXPath
> Issue Type: Bug
> Affects Versions: 1.2 Final
> Environment: WInXP, Java 1.5, Eclipse 3.2
> Reporter: John Attwood
>
> String returned by Pointer.asPath() is incorrect when path starts with '//' and target is a collection. The path returned always has a final subscript equal to the size of the collection, although Pointer.getValue() still returns the correct element in each case. Below are two classes and a JUnit testcase which reproduce the bug and isolate it to the case where the path starts with '//' and the target is a collection.
> I found this problem whilst trying to write the equivalent of XPathExplorer for my JXPath-based object trees. It does't affect the main app, as getValue() always returns the correct node, but in my explorer it only ever highlights the last element in any collection (the objects in my trees aren't always unique so the path is only way to identify them individually and allow the matching nodes to be highlighted).
> Otherwise an excellent, easy-to-use and really useful package.
> /////////////////////////////////////// Parent.java //////////////////////////////////////////////////////////////////////////////////
> package test;
> import java.util.ArrayList;
> public class Parent {
> private int id;
> private ArrayList<Child> kids;
> public Parent(int id) {
> this.id = id;
> this.kids = new ArrayList<Child>();
> }
> public int getId() {
> return id;
> }
> public ArrayList<Child> getKids() {
> return kids;
> }
> public void addKid(Child kid) {
> kids.add(kid);
> }
> public void setId(int id) {
> this.id = id;
> }
> public void setKids(ArrayList<Child> kids) {
> this.kids = kids;
> }
> }
> /////////////////////////////////////////////////////////// Child.java /////////////////////////////////////////////////////////////////////////////////////////////////////////////
> package test;
> public class Child {
> private int id;
> public Child(int id) {
> this.id = id;
> }
> public int getId() {
> return id;
> }
> public void setId(int id) {
> this.id = id;
> }
> }
> /////////////////////////////////////////////////////////// TestPointerToPath.java ///////////////////////////////////////////////////////////////////////////
> package test;
> import java.util.HashSet;
> import java.util.Iterator;
> import java.util.Set;
> import junit.framework.TestCase;
> import org.apache.commons.jxpath.JXPathContext;
> import org.apache.commons.jxpath.Pointer;
> public class TestPonterToPath extends TestCase {
> private Parent parent;
> private Set<String> expectedPaths, actualPaths;
> private Set<Object> actualObjects, expectedObjects;
> private JXPathContext ctx;
>
> private static final int SIZE = 4;
>
> public void setUp() {
> parent = new Parent(1);
> for (int i = 1; i <= SIZE; i++) {
> parent.addKid(new Child(i));
> }
> expectedPaths = new HashSet<String>();
> expectedObjects = new HashSet<Object>();
> actualPaths = new HashSet<String>();
> actualObjects = new HashSet<Object>();
> ctx = JXPathContext.newContext(parent);
> }
>
> private void doExpected(String path1, String path2) {
> for (int i = 1; i <= SIZE; i++) {
> Pointer p = ctx.getPointer(path1 + i + path2);
> expectedPaths.add(p.asPath());
> expectedObjects.add(p.getValue());
> }
> assertEquals(SIZE, expectedPaths.size());
> assertEquals(SIZE, expectedObjects.size());
> }
>
> private void doActual(String path) {
> Iterator it = ctx.iteratePointers(path);
> while (it.hasNext()) {
> Pointer p = (Pointer) it.next();
> actualPaths.add(p.asPath());
> actualObjects.add(p.getValue());
> }
> assertEquals(SIZE, actualObjects.size());
> }
> public void testToPathLeafAbs() {
> doExpected("/kids[", "]/id");
> doActual("/kids/id");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
> public void testToPathLeafRel() {
> doExpected("//kids[", "]/id");
> doActual("//kids/id");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
> public void testToPathCollectionAbs() {
> doExpected("/kids[", "]");
> doActual("/kids");
> assertEquals(expectedObjects, actualObjects);
> assertEquals(expectedPaths, actualPaths);
> }
>
> public void testToPathCollectionRel() {
> doExpected("//kids[", "]");
> doActual("//kids");
> assertEquals(expectedObjects, actualObjects);
> /* next test fails as all actualPaths are /kids[SIZE] */
> assertEquals(expectedPaths, actualPaths);
> }
>
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org