Skip to content

Commit

Permalink
PIVOT-282 :: Fix illegal item modification check in ArrayList.update()
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/incubator/pivot/trunk@812461 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Todd Volkert committed Sep 8, 2009
1 parent 69626c5 commit 000f71b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions core/src/org/apache/pivot/collections/ArrayList.java
Expand Up @@ -259,9 +259,18 @@ public T update(int index, T item) {
T previousItem = (T)items[index];

if (previousItem != item) {
if (comparator != null
&& binarySearch(this, item, comparator) != index) {
throw new IllegalArgumentException("Illegal item modification.");
if (comparator != null) {
// Ensure that the new item is greater or equal to its
// predecessor and less than or equal to its successor
T predecessorItem = (index > 0 ? (T)items[index - 1] : null);
T successorItem = (index < length - 1 ? (T)items[index + 1] : null);

if ((predecessorItem != null
&& comparator.compare(item, predecessorItem) == -1)
|| (successorItem != null
&& comparator.compare(item, successorItem) == 1)) {
throw new IllegalArgumentException("Illegal item modification.");
}
}

items[index] = item;
Expand Down

0 comments on commit 000f71b

Please sign in to comment.