Skip to content

Commit

Permalink
Use fullCurrentPath() when relativizing includes, and make it throw i…
Browse files Browse the repository at this point in the history
…f path is empty

This is just to consolidate our use of pathStack in one place.
  • Loading branch information
havocp committed May 1, 2014
1 parent 36c1392 commit e5cc232
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions config/src/main/java/com/typesafe/config/impl/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -683,9 +679,7 @@ private void parseInclude(Map<String, AbstractConfigValue> 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);
}

Expand Down

0 comments on commit e5cc232

Please sign in to comment.