From 8625b7875372038e5d02e949280dbc0c47dfa968 Mon Sep 17 00:00:00 2001 From: vgolub Date: Fri, 7 Sep 2018 18:13:23 +0300 Subject: [PATCH 1/2] #584 Add root config origin to exception --- .../src/main/java/com/typesafe/config/ConfigException.java | 5 +++++ config/src/main/java/com/typesafe/config/impl/Path.java | 4 ++-- .../src/main/java/com/typesafe/config/impl/SimpleConfig.java | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/config/src/main/java/com/typesafe/config/ConfigException.java b/config/src/main/java/com/typesafe/config/ConfigException.java index fce04b407..f781b3755 100644 --- a/config/src/main/java/com/typesafe/config/ConfigException.java +++ b/config/src/main/java/com/typesafe/config/ConfigException.java @@ -8,6 +8,7 @@ import java.lang.reflect.Field; import com.typesafe.config.impl.ConfigImplUtil; +import com.typesafe.config.impl.Path; /** * All exceptions thrown by the library are subclasses of @@ -126,6 +127,10 @@ public Missing(String path, Throwable cause) { cause); } + public Missing(ConfigOrigin origin, Path path) { + this(origin, "No configuration setting found for key '" + path.render() + "'"); + } + public Missing(String path) { this(path, null); } 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 d39a57c68..1e0fd7471 100644 --- a/config/src/main/java/com/typesafe/config/impl/Path.java +++ b/config/src/main/java/com/typesafe/config/impl/Path.java @@ -7,7 +7,7 @@ import com.typesafe.config.ConfigException; -final class Path { +public final class Path { final private String first; final private Path remainder; @@ -216,7 +216,7 @@ public String toString() { * toString() is a debugging-oriented version while this is an * error-message-oriented human-readable one. */ - String render() { + public String render() { StringBuilder sb = new StringBuilder(); appendToStringBuilder(sb); return sb.toString(); diff --git a/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java b/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java index ce1913adb..308d14ca7 100644 --- a/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java +++ b/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java @@ -153,7 +153,7 @@ static private AbstractConfigValue findKeyOrNull(AbstractConfigObject self, Stri ConfigValueType expected, Path originalPath) { AbstractConfigValue v = self.peekAssumingResolved(key, originalPath); if (v == null) - throw new ConfigException.Missing(originalPath.render()); + throw new ConfigException.Missing(self.origin(), originalPath); if (expected != null) v = DefaultTransformer.transform(v, expected); From 743f240d478b931b34c20b26933220d727cebbc9 Mon Sep 17 00:00:00 2001 From: vgolub Date: Fri, 7 Sep 2018 20:25:46 +0300 Subject: [PATCH 2/2] Do not pass Path object as exception argument --- .../main/java/com/typesafe/config/ConfigException.java | 8 ++------ config/src/main/java/com/typesafe/config/impl/Path.java | 4 ++-- .../main/java/com/typesafe/config/impl/SimpleConfig.java | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/config/src/main/java/com/typesafe/config/ConfigException.java b/config/src/main/java/com/typesafe/config/ConfigException.java index f781b3755..f35e8dbea 100644 --- a/config/src/main/java/com/typesafe/config/ConfigException.java +++ b/config/src/main/java/com/typesafe/config/ConfigException.java @@ -8,7 +8,6 @@ import java.lang.reflect.Field; import com.typesafe.config.impl.ConfigImplUtil; -import com.typesafe.config.impl.Path; /** * All exceptions thrown by the library are subclasses of @@ -127,8 +126,8 @@ public Missing(String path, Throwable cause) { cause); } - public Missing(ConfigOrigin origin, Path path) { - this(origin, "No configuration setting found for key '" + path.render() + "'"); + public Missing(ConfigOrigin origin, String path) { + this(origin, "No configuration setting found for key '" + path + "'", null); } public Missing(String path) { @@ -139,9 +138,6 @@ protected Missing(ConfigOrigin origin, String message, Throwable cause) { super(origin, message, cause); } - protected Missing(ConfigOrigin origin, String message) { - this(origin, message, null); - } } /** 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 1e0fd7471..d39a57c68 100644 --- a/config/src/main/java/com/typesafe/config/impl/Path.java +++ b/config/src/main/java/com/typesafe/config/impl/Path.java @@ -7,7 +7,7 @@ import com.typesafe.config.ConfigException; -public final class Path { +final class Path { final private String first; final private Path remainder; @@ -216,7 +216,7 @@ public String toString() { * toString() is a debugging-oriented version while this is an * error-message-oriented human-readable one. */ - public String render() { + String render() { StringBuilder sb = new StringBuilder(); appendToStringBuilder(sb); return sb.toString(); diff --git a/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java b/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java index 308d14ca7..c0d6b65c7 100644 --- a/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java +++ b/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java @@ -153,7 +153,7 @@ static private AbstractConfigValue findKeyOrNull(AbstractConfigObject self, Stri ConfigValueType expected, Path originalPath) { AbstractConfigValue v = self.peekAssumingResolved(key, originalPath); if (v == null) - throw new ConfigException.Missing(self.origin(), originalPath); + throw new ConfigException.Missing(self.origin(), originalPath.render()); if (expected != null) v = DefaultTransformer.transform(v, expected);