From e5cc23235f374004b86bf7395201763bc7e9085c Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Thu, 1 May 2014 10:15:44 -0400 Subject: [PATCH] Use fullCurrentPath() when relativizing includes, and make it throw if path is empty This is just to consolidate our use of pathStack in one place. --- .../java/com/typesafe/config/impl/Parser.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) 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); }