[COLLECTIONS-701] StackOverflowError in SetUniqueList.add() when it
receives itself. Closes #57.
This commit is contained in:
parent
dc828f8b16
commit
1979a6e310
|
@ -36,6 +36,9 @@
|
||||||
<action issue="COLLECTIONS-696" dev="ggregory" type="add" due-to="Maxim Solodovnik">
|
<action issue="COLLECTIONS-696" dev="ggregory" type="add" due-to="Maxim Solodovnik">
|
||||||
AbstractReferenceMap made easier for subclassing; PR #51.
|
AbstractReferenceMap made easier for subclassing; PR #51.
|
||||||
</action>
|
</action>
|
||||||
|
<action issue="COLLECTIONS-701" dev="ggregory" type="fix" due-to="Don Jeba">
|
||||||
|
StackOverflowError in SetUniqueList.add() when it receives itself.
|
||||||
|
</action>
|
||||||
</release>
|
</release>
|
||||||
<release version="4.2" date="2018-07-11" description="Update from Java 6 to Java 7, bug fixes, and small changes.">
|
<release version="4.2" date="2018-07-11" description="Update from Java 6 to Java 7, bug fixes, and small changes.">
|
||||||
<action issue="COLLECTIONS-681" dev="kinow" type="add" due-to="Stephan Fuhrmann">
|
<action issue="COLLECTIONS-681" dev="kinow" type="add" due-to="Stephan Fuhrmann">
|
||||||
|
|
|
@ -149,8 +149,8 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
|
||||||
public void add(final int index, final E object) {
|
public void add(final int index, final E object) {
|
||||||
// adds element if it is not contained already
|
// adds element if it is not contained already
|
||||||
if (set.contains(object) == false) {
|
if (set.contains(object) == false) {
|
||||||
super.add(index, object);
|
|
||||||
set.add(object);
|
set.add(object);
|
||||||
|
super.add(index, object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,6 @@ public class Collections701Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void testSetUniqueList() {
|
public void testSetUniqueList() {
|
||||||
final List<Object> source = new ArrayList<>();
|
final List<Object> source = new ArrayList<>();
|
||||||
final List<Object> list = SetUniqueList.setUniqueList(source);
|
final List<Object> list = SetUniqueList.setUniqueList(source);
|
||||||
|
|
|
@ -139,6 +139,7 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> {
|
||||||
assertEquals("Size should increase after addAll",
|
assertEquals("Size should increase after addAll",
|
||||||
size + elements.length, getCollection().size());
|
size + elements.length, getCollection().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void testCollectionIteratorRemove() {
|
public void testCollectionIteratorRemove() {
|
||||||
try {
|
try {
|
||||||
|
@ -148,7 +149,6 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> {
|
||||||
extraVerify = true;
|
extraVerify = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCollections304() {
|
public void testCollections304() {
|
||||||
final List<String> list = new LinkedList<>();
|
final List<String> list = new LinkedList<>();
|
||||||
final SetUniqueList<String> decoratedList = SetUniqueList.setUniqueList(list);
|
final SetUniqueList<String> decoratedList = SetUniqueList.setUniqueList(list);
|
||||||
|
@ -213,6 +213,31 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> {
|
||||||
assertFalse(subUniqueList.contains("World")); // fails
|
assertFalse(subUniqueList.contains("World")); // fails
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCollections701() {
|
||||||
|
final SetUniqueList<Object> uniqueList = new SetUniqueList<>(new ArrayList<>(), new HashSet<>());
|
||||||
|
final Integer obj1 = Integer.valueOf(1);
|
||||||
|
final Integer obj2 = Integer.valueOf(2);
|
||||||
|
uniqueList.add(obj1);
|
||||||
|
uniqueList.add(obj2);
|
||||||
|
assertEquals(2, uniqueList.size());
|
||||||
|
uniqueList.add(uniqueList);
|
||||||
|
assertEquals(3, uniqueList.size());
|
||||||
|
final List<Object> list = new LinkedList<>();
|
||||||
|
final SetUniqueList<Object> decoratedList = SetUniqueList.setUniqueList(list);
|
||||||
|
final String s1 = "Apple";
|
||||||
|
final String s2 = "Lemon";
|
||||||
|
final String s3 = "Orange";
|
||||||
|
final String s4 = "Strawberry";
|
||||||
|
decoratedList.add(s1);
|
||||||
|
decoratedList.add(s2);
|
||||||
|
decoratedList.add(s3);
|
||||||
|
assertEquals(3, decoratedList.size());
|
||||||
|
decoratedList.set(1, s4);
|
||||||
|
assertEquals(3, decoratedList.size());
|
||||||
|
decoratedList.add(decoratedList);
|
||||||
|
assertEquals(4, decoratedList.size());
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public void testFactory() {
|
public void testFactory() {
|
||||||
final Integer[] array = new Integer[] { Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(1) };
|
final Integer[] array = new Integer[] { Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(1) };
|
||||||
|
|
Loading…
Reference in New Issue