Thomas Bürli created COLLECTIONS-770:
----------------------------------------
Summary: ToString method is unresponsive after multiple SetUtils
union calls
Key: COLLECTIONS-770
URL: https://issues.apache.org/jira/browse/COLLECTIONS-770
Project: Commons Collections
Issue Type: Bug
Affects Versions: 4.4
Reporter: Thomas Bürli
Attachments: SetUtilsTest.java, stackdump.txt
I had the following code and my application stopped responsing as soon the
number of names for a userId got too big.
{code:java}
Map<String, Set<String>> stringMap = new TreeMap<>();
for (String name : names) {
for (String userId : userIds) {
stringMap.merge(userId, Collections.singleton(name),
SetUtils::union);
}
}
{code}
I did some debugging and it occurs when the toString method of one the set is
called. It looks like the issues is with the iterator of "SetUtils.SetView".
Here just the method I used to create test sets and in the attachment you find
the full tests class and a stack dump. The execution time is growing
exponentially with the numbers of times the SetUtils.union is called. So for 29
elements it took 16 seconds to execute toString, and with 30 it took 32 seconds.
{code:java}
@Test
void setWith20Elements() {
assertTimeout(ofSeconds(2), () -> createSet(30).toString());
}
Set<String> createSet(int number) {
List<String> inputs = new ArrayList<>();
for (int i = 0; i < number; i++) {
inputs.add("Test"+ i);
}
Set<String> testSet = Collections.singleton("String1");
for (String element : inputs) {
Set<String> part = Collections.singleton(element);
testSet = SetUtils.union(testSet,part);
}
return testSet;
}
{code}
Thanks for your support
--
This message was sent by Atlassian Jira
(v8.3.4#803005)