[ https://issues.apache.org/jira/browse/PIVOT-533?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Greg Brown resolved PIVOT-533. ------------------------------ Resolution: Fixed > org.apache.pivot.collections.Sequence.Tree - add, get, insert, remove & > update methods do not handle empty Paths > ---------------------------------------------------------------------------------------------------------------- > > Key: PIVOT-533 > URL: https://issues.apache.org/jira/browse/PIVOT-533 > Project: Pivot > Issue Type: Bug > Components: core-collections > Affects Versions: 1.5 > Reporter: Chris Bartlett > Priority: Minor > Fix For: 1.5.1 > > > The javadocs for > org.apache.pivot.collections.Sequence.Tree#get(Sequence<T> sequence, Path > path) > state that it will return null if supplied with an 'empty' path. > The method only actually checks for a null Path, and not for an empty one > (assuming empty means path.getLength() == 0) > resulting in > java.lang.IndexOutOfBoundsException: index 0 out of bounds. > This has a knock on effect with > add, insert, remove & update methods in the same class. > public class SequenceTest { > public static void main(String[] args) { > final Path emptyPath = new Path(); > final TreeBranch branch = new TreeBranch("xxx"); > final List<TreeNode> data = new ArrayList<TreeNode>(new > TreeNode("aaa"), new TreeBranch("bbb"), new TreeNode("ccc"), branch); > // Succeeds > Sequence.Tree.get(data, new Path(0)); > try { > // Fails with java.lang.IllegalArgumentException: path is null. > (as expected) > Sequence.Tree.get(data, null); > } catch (java.lang.IllegalArgumentException e) { > // Expected > } > // Fails with java.lang.IndexOutOfBoundsException: index 0 out of > bounds. > Sequence.Tree.get(data, emptyPath); > // Fails with java.lang.IndexOutOfBoundsException: index 0 out of > bounds. > Sequence.Tree.add(data, new TreeBranch("eee"), emptyPath); > // Fails with java.lang.IndexOutOfBoundsException: index 0 out of > bounds. > Sequence.Tree.insert(data, new TreeBranch("fff"), emptyPath, 0); > // Succeeds > Sequence.Tree.remove(data, branch); > // Fails with java.lang.IndexOutOfBoundsException: index 0 out of > bounds. > Sequence.Tree.remove(data, emptyPath, 1); > // Fails with java.lang.IndexOutOfBoundsException: index 0 out of > bounds. > Sequence.Tree.update(data, emptyPath, new TreeBranch("ggg")); > } > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.