Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 99830 invoked from network); 3 Jan 2007 23:55:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Jan 2007 23:55:51 -0000 Received: (qmail 78106 invoked by uid 500); 3 Jan 2007 23:55:55 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 78039 invoked by uid 500); 3 Jan 2007 23:55:55 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 78028 invoked by uid 99); 3 Jan 2007 23:55:54 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Jan 2007 15:55:54 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Jan 2007 15:55:47 -0800 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 8038D714326 for ; Wed, 3 Jan 2007 15:55:27 -0800 (PST) Message-ID: <22577051.1167868527506.JavaMail.jira@brutus> Date: Wed, 3 Jan 2007 15:55:27 -0800 (PST) From: "Matt Benson (JIRA)" To: commons-dev@jakarta.apache.org Subject: [jira] Commented: (JXPATH-71) Ponter.asPath() return values not always correct In-Reply-To: <16522705.1160402239708.JavaMail.root@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on 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 kids; > public Parent(int id) { > this.id = id; > this.kids = new ArrayList(); > } > public int getId() { > return id; > } > public ArrayList getKids() { > return kids; > } > public void addKid(Child kid) { > kids.add(kid); > } > public void setId(int id) { > this.id = id; > } > public void setKids(ArrayList 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 expectedPaths, actualPaths; > private Set 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(); > expectedObjects = new HashSet(); > actualPaths = new HashSet(); > actualObjects = new HashSet(); > 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