Fix index out of bounds error

Fix an array index out of bounds error, which would occur if
a complex value was inserted into an empty root in a
ConfigDocument.
This commit is contained in:
Preben Ingvaldsen 2015-06-30 14:01:43 -07:00
parent 398406378d
commit 919c46accc
2 changed files with 8 additions and 1 deletions

View File

@ -170,7 +170,7 @@ final class ConfigNodeObject extends ConfigNodeComplexValue {
// If the value we're inserting is a complex value, we'll need to indent it for insertion
AbstractConfigNodeValue indentedValue;
if (value instanceof ConfigNodeComplexValue) {
if (value instanceof ConfigNodeComplexValue && !indentation.isEmpty()) {
indentedValue = ((ConfigNodeComplexValue) value).indentText(indentation.get(indentation.size() - 1));
} else {
indentedValue = value;

View File

@ -436,6 +436,13 @@ class ConfigDocumentTest extends TestUtils {
val configDocument = ConfigDocumentFactory.parseString(origText)
assertEquals("a : 1", configDocument.withValueText("a", "1").render)
val mapVal = ConfigValueFactory.fromAnyRef(Map("a" -> 1, "b" -> 2).asJava)
assertEquals("a : {\n # hardcoded value\n \"a\" : 1,\n # hardcoded value\n \"b\" : 2\n}",
configDocument.withValue("a", mapVal).render)
val arrayVal = ConfigValueFactory.fromAnyRef(List(1, 2).asJava)
assertEquals("a : [\n # hardcoded value\n 1,\n # hardcoded value\n 2\n]", configDocument.withValue("a", arrayVal).render)
}
@Test