diff --git a/config/src/main/java/com/typesafe/config/impl/Parser.java b/config/src/main/java/com/typesafe/config/impl/Parser.java index 94c6189a..83da109a 100644 --- a/config/src/main/java/com/typesafe/config/impl/Parser.java +++ b/config/src/main/java/com/typesafe/config/impl/Parser.java @@ -683,7 +683,9 @@ final class Parser { } if (!pathStack.isEmpty()) { - Path prefix = new Path(pathStack); + // The stack is in reverse order (most recent first on the + // iterator), so build the path from the reversed iterator. + Path prefix = new Path(pathStack.descendingIterator()); obj = obj.relativized(prefix); } diff --git a/config/src/main/java/com/typesafe/config/impl/Path.java b/config/src/main/java/com/typesafe/config/impl/Path.java index dec48582..c3b8f39e 100644 --- a/config/src/main/java/com/typesafe/config/impl/Path.java +++ b/config/src/main/java/com/typesafe/config/impl/Path.java @@ -35,10 +35,14 @@ final class Path { // append all the paths in the list together into one path Path(List pathsToConcat) { - if (pathsToConcat.isEmpty()) + this(pathsToConcat.iterator()); + } + + // append all the paths in the iterator together into one path + Path(Iterator i) { + if (!i.hasNext()) throw new ConfigException.BugOrBroken("empty path"); - Iterator i = pathsToConcat.iterator(); Path firstPath = i.next(); this.first = firstPath.first; diff --git a/config/src/test/resources/test10.conf b/config/src/test/resources/test10.conf index 4d0bb955..6d0a3927 100644 --- a/config/src/test/resources/test10.conf +++ b/config/src/test/resources/test10.conf @@ -3,3 +3,9 @@ foo { include "test09.conf" } + +bar { + nested { + include "test09.conf" + } +} diff --git a/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala b/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala index 8c58a510..d26cb997 100644 --- a/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala +++ b/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala @@ -1029,6 +1029,10 @@ class ConfigTest extends TestUtils { assertEquals(3, resolved.getInt("foo.a.c")) assertEquals(5, resolved.getInt("foo.b")) assertEquals(10, resolved.getInt("foo.a.q")) + + assertEquals(3, resolved.getInt("bar.nested.a.c")) + assertEquals(5, resolved.getInt("bar.nested.b")) + assertEquals(10, resolved.getInt("bar.nested.a.q")) } @Test