Skip to content

Commit 56b5c4d

Browse files
committed
[CONFIGURATION-840] StackOverflowError when adding property in
AbstractListDelimiterHandler.flattenIterator()
1 parent ea0f24c commit 56b5c4d

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/changes/changes.xml

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
</properties>
2525
<body>
2626
<release version="2.10.1" date="YYYY-MM-DD" description="Minor release with new features and updated dependencies.">
27+
<!-- FIX -->
28+
<action type="fix" issue="CONFIGURATION-840" dev="ggregory" due-to="Gary Gregory">StackOverflowError when adding property in AbstractListDelimiterHandler.flattenIterator().</action>
2729
<!-- UPDATE -->
2830
<action type="update" dev="ggregory" due-to="Dependabot">Bump jackson-databind from 2.16.1 to 2.17.0 #297, #303, #326, #331, #340, #378.</action>
2931
<action type="update" dev="ggregory" due-to="Dependabot">Bump log4j.version from 2.23.0 to 2.23.1 #379.</action>

src/main/java/org/apache/commons/configuration2/convert/ListDelimiterHandler.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.commons.configuration2.convert;
1818

1919
import java.lang.reflect.Array;
20+
import java.nio.file.Path;
2021
import java.util.Collection;
2122
import java.util.Iterator;
2223
import java.util.LinkedList;
@@ -121,7 +122,10 @@ default Collection<?> flatten(final Object value, final int limit) {
121122
return split((String) value, true);
122123
}
123124
final Collection<Object> result = new LinkedList<>();
124-
if (value instanceof Iterable) {
125+
if (value instanceof Path) {
126+
// Don't handle as an Iterable.
127+
result.add(value);
128+
} else if (value instanceof Iterable) {
125129
AbstractListDelimiterHandler.flattenIterator(this, result, ((Iterable<?>) value).iterator(), limit);
126130
} else if (value instanceof Iterator) {
127131
AbstractListDelimiterHandler.flattenIterator(this, result, (Iterator<?>) value, limit);

src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java

+16
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
import java.net.URLConnection;
5252
import java.net.URLStreamHandler;
5353
import java.nio.charset.StandardCharsets;
54+
import java.nio.file.FileSystems;
5455
import java.nio.file.Files;
56+
import java.nio.file.Path;
5557
import java.nio.file.Paths;
5658
import java.util.ArrayDeque;
5759
import java.util.ArrayList;
@@ -433,6 +435,20 @@ public void testComment() {
433435
assertFalse(conf.containsKey("!comment"));
434436
}
435437

438+
@Test
439+
public void testCompress840() {
440+
final PropertiesConfiguration configuration = new PropertiesConfiguration();
441+
final Path path = FileSystems.getDefault().getPath("bar");
442+
final ListDelimiterHandler listDelimiterHandler = configuration.getListDelimiterHandler();
443+
listDelimiterHandler.flatten(path, 0);
444+
// Stack overflow:
445+
listDelimiterHandler.flatten(path, 1);
446+
listDelimiterHandler.flatten(path, Integer.MAX_VALUE);
447+
listDelimiterHandler.parse(path);
448+
configuration.addProperty("foo", path);
449+
configuration.toString();
450+
}
451+
436452
/**
437453
* Tests copying another configuration into the test configuration. This test ensures that the layout object is informed
438454
* about the newly added properties.

0 commit comments

Comments
 (0)