You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by "Chris Bartlett (JIRA)" <ji...@apache.org> on 2010/06/19 19:56:22 UTC

[jira] Created: (PIVOT-533) org.apache.pivot.collections.Sequence.Tree - add, get, insert, remove & update methods do not handle empty Paths

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.


[jira] Resolved: (PIVOT-533) org.apache.pivot.collections.Sequence.Tree - add, get, insert, remove & update methods do not handle empty Paths

Posted by "Greg Brown (JIRA)" <ji...@apache.org>.
     [ 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.


[jira] Commented: (PIVOT-533) org.apache.pivot.collections.Sequence.Tree - add, get, insert, remove & update methods do not handle empty Paths

Posted by "Sandro Martini (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIVOT-533?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12880678#action_12880678 ] 

Sandro Martini commented on PIVOT-533:
--------------------------------------

Hi,
before making the patch, are there any problems using the test case here shown in our code base, or is it safe because it's here (or should be attached in a zip, attached with the right permission) ? Sorry, I don't remember ...

After I can do the fix, tell me.

Bye,
Sandro


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