Do not pass Path object as exception argument

This commit is contained in:
vgolub 2018-09-07 20:25:46 +03:00
parent 8625b78753
commit 743f240d47
3 changed files with 5 additions and 9 deletions

View File

@ -8,7 +8,6 @@ import java.io.Serializable;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import com.typesafe.config.impl.ConfigImplUtil; import com.typesafe.config.impl.ConfigImplUtil;
import com.typesafe.config.impl.Path;
/** /**
* All exceptions thrown by the library are subclasses of * All exceptions thrown by the library are subclasses of
@ -127,8 +126,8 @@ public abstract class ConfigException extends RuntimeException implements Serial
cause); cause);
} }
public Missing(ConfigOrigin origin, Path path) { public Missing(ConfigOrigin origin, String path) {
this(origin, "No configuration setting found for key '" + path.render() + "'"); this(origin, "No configuration setting found for key '" + path + "'", null);
} }
public Missing(String path) { public Missing(String path) {
@ -139,9 +138,6 @@ public abstract class ConfigException extends RuntimeException implements Serial
super(origin, message, cause); super(origin, message, cause);
} }
protected Missing(ConfigOrigin origin, String message) {
this(origin, message, null);
}
} }
/** /**

View File

@ -7,7 +7,7 @@ import java.util.*;
import com.typesafe.config.ConfigException; import com.typesafe.config.ConfigException;
public final class Path { final class Path {
final private String first; final private String first;
final private Path remainder; final private Path remainder;
@ -216,7 +216,7 @@ public final class Path {
* toString() is a debugging-oriented version while this is an * toString() is a debugging-oriented version while this is an
* error-message-oriented human-readable one. * error-message-oriented human-readable one.
*/ */
public String render() { String render() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
appendToStringBuilder(sb); appendToStringBuilder(sb);
return sb.toString(); return sb.toString();

View File

@ -153,7 +153,7 @@ final class SimpleConfig implements Config, MergeableValue, Serializable {
ConfigValueType expected, Path originalPath) { ConfigValueType expected, Path originalPath) {
AbstractConfigValue v = self.peekAssumingResolved(key, originalPath); AbstractConfigValue v = self.peekAssumingResolved(key, originalPath);
if (v == null) if (v == null)
throw new ConfigException.Missing(self.origin(), originalPath); throw new ConfigException.Missing(self.origin(), originalPath.render());
if (expected != null) if (expected != null)
v = DefaultTransformer.transform(v, expected); v = DefaultTransformer.transform(v, expected);