Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 67EBAF1C5 for ; Sat, 27 Apr 2013 11:57:25 +0000 (UTC) Received: (qmail 42524 invoked by uid 500); 27 Apr 2013 11:57:25 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 42422 invoked by uid 500); 27 Apr 2013 11:57:24 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 42395 invoked by uid 99); 27 Apr 2013 11:57:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Apr 2013 11:57:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Apr 2013 11:57:22 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7A92B238899C; Sat, 27 Apr 2013 11:57:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1476557 - in /commons/proper/collections/trunk/src: changes/changes.xml main/java/org/apache/commons/collections4/list/SetUniqueList.java test/java/org/apache/commons/collections4/list/SetUniqueListTest.java Date: Sat, 27 Apr 2013 11:57:02 -0000 To: commits@commons.apache.org From: tn@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130427115702.7A92B238899C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tn Date: Sat Apr 27 11:57:01 2013 New Revision: 1476557 URL: http://svn.apache.org/r1476557 Log: [COLLECTIONS-310] SetUniqueList#subList now returns an unmodifiable list. Modified: commons/proper/collections/trunk/src/changes/changes.xml commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java Modified: commons/proper/collections/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/changes/changes.xml?rev=1476557&r1=1476556&r2=1476557&view=diff ============================================================================== --- commons/proper/collections/trunk/src/changes/changes.xml (original) +++ commons/proper/collections/trunk/src/changes/changes.xml Sat Apr 27 11:57:01 2013 @@ -276,6 +276,10 @@ Use of final keyword where applicable, minor performance improvements by properly initializing the capacity of newly created collections when known in advance. + + "SetUniqueList#subList()" will now return an unmodifiable list as changes to it + may invalidate the parent list. + "SetUniqueList#subList()#contains(Object)" will now correctly check the subList rather than the parent list. Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java?rev=1476557&r1=1476556&r2=1476557&view=diff ============================================================================== --- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java (original) +++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java Sat Apr 27 11:57:01 2013 @@ -24,6 +24,7 @@ import java.util.List; import java.util.ListIterator; import java.util.Set; +import org.apache.commons.collections4.ListUtils; import org.apache.commons.collections4.set.UnmodifiableSet; import org.apache.commons.collections4.iterators.AbstractIteratorDecorator; import org.apache.commons.collections4.iterators.AbstractListIteratorDecorator; @@ -319,11 +320,17 @@ public class SetUniqueList extends Ab return new SetListListIterator(super.listIterator(index), set); } + /** + * {@inheritDoc} + *

+ * NOTE: from 4.0, an unmodifiable list will be returned, as changes to the + * subList can invalidate the parent list. + */ @Override public List subList(final int fromIndex, final int toIndex) { final List superSubList = super.subList(fromIndex, toIndex); final Set subSet = createSetBasedOnList(set, superSubList); - return new SetUniqueList(superSubList, subSet); + return ListUtils.unmodifiableList(new SetUniqueList(superSubList, subSet)); } /** Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java?rev=1476557&r1=1476556&r2=1476557&view=diff ============================================================================== --- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java (original) +++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java Sat Apr 27 11:57:01 2013 @@ -43,6 +43,7 @@ public class SetUniqueListTest extend return new SetUniqueList(new ArrayList(), new HashSet()); } + //----------------------------------------------------------------------- @Override public void testListIteratorSet() { // override to block @@ -461,6 +462,16 @@ public class SetUniqueListTest extend assertEquals(4, decoratedList.size()); } + public void testSubListIsUnmodifiable() { + resetFull(); + List subList = getCollection().subList(1, 3); + try { + subList.remove(0); + fail("subList should be unmodifiable"); + } catch (UnsupportedOperationException e) { + // expected + } + } @SuppressWarnings("unchecked") public void testCollections307() { List list = new ArrayList();