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 83da109a8..4969255ad 100644 --- a/config/src/main/java/com/typesafe/config/impl/Parser.java +++ b/config/src/main/java/com/typesafe/config/impl/Parser.java @@ -440,15 +440,11 @@ private String previousFieldName(Path lastPath) { } private Path fullCurrentPath() { - Path full = null; // pathStack has top of stack at front - for (Path p : pathStack) { - if (full == null) - full = p; - else - full = full.prepend(p); - } - return full; + if (pathStack.isEmpty()) + throw new ConfigException.BugOrBroken("Bug in parser; tried to get current path when at root"); + else + return new Path(pathStack.descendingIterator()); } private String previousFieldName() { @@ -683,9 +679,7 @@ private void parseInclude(Map values) { } if (!pathStack.isEmpty()) { - // 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()); + Path prefix = fullCurrentPath(); obj = obj.relativized(prefix); }