mirror of
https://github.com/lightbend/config.git
synced 2025-02-15 22:00:52 +08:00
When using "singleton holder" catch ExceptionInInitializerError and pull out the ConfigException if any
This commit is contained in:
parent
62628b6404
commit
4896b7d75d
@ -11,6 +11,7 @@ import java.util.Map;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import com.typesafe.config.impl.ConfigImpl;
|
import com.typesafe.config.impl.ConfigImpl;
|
||||||
|
import com.typesafe.config.impl.ConfigUtil;
|
||||||
import com.typesafe.config.impl.Parseable;
|
import com.typesafe.config.impl.Parseable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -173,7 +174,11 @@ public final class ConfigFactory {
|
|||||||
* @return configuration for an application
|
* @return configuration for an application
|
||||||
*/
|
*/
|
||||||
public static Config load() {
|
public static Config load() {
|
||||||
return DefaultConfigHolder.defaultConfig;
|
try {
|
||||||
|
return DefaultConfigHolder.defaultConfig;
|
||||||
|
} catch (ExceptionInInitializerError e) {
|
||||||
|
throw ConfigUtil.extractInitializerError(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -305,7 +305,11 @@ public class ConfigImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ConfigIncluder defaultIncluder() {
|
static ConfigIncluder defaultIncluder() {
|
||||||
return DefaultIncluderHolder.defaultIncluder;
|
try {
|
||||||
|
return DefaultIncluderHolder.defaultIncluder;
|
||||||
|
} catch (ExceptionInInitializerError e) {
|
||||||
|
throw ConfigUtil.extractInitializerError(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AbstractConfigObject loadSystemProperties() {
|
private static AbstractConfigObject loadSystemProperties() {
|
||||||
@ -319,7 +323,11 @@ public class ConfigImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static AbstractConfigObject systemPropertiesAsConfigObject() {
|
static AbstractConfigObject systemPropertiesAsConfigObject() {
|
||||||
return SystemPropertiesHolder.systemProperties;
|
try {
|
||||||
|
return SystemPropertiesHolder.systemProperties;
|
||||||
|
} catch (ExceptionInInitializerError e) {
|
||||||
|
throw ConfigUtil.extractInitializerError(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** For use ONLY by library internals, DO NOT TOUCH not guaranteed ABI */
|
/** For use ONLY by library internals, DO NOT TOUCH not guaranteed ABI */
|
||||||
@ -351,7 +359,11 @@ public class ConfigImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static AbstractConfigObject envVariablesAsConfigObject() {
|
static AbstractConfigObject envVariablesAsConfigObject() {
|
||||||
return EnvVariablesHolder.envVariables;
|
try {
|
||||||
|
return EnvVariablesHolder.envVariables;
|
||||||
|
} catch (ExceptionInInitializerError e) {
|
||||||
|
throw ConfigUtil.extractInitializerError(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** For use ONLY by library internals, DO NOT TOUCH not guaranteed ABI */
|
/** For use ONLY by library internals, DO NOT TOUCH not guaranteed ABI */
|
||||||
@ -369,6 +381,10 @@ public class ConfigImpl {
|
|||||||
|
|
||||||
/** For use ONLY by library internals, DO NOT TOUCH not guaranteed ABI */
|
/** For use ONLY by library internals, DO NOT TOUCH not guaranteed ABI */
|
||||||
public static Config defaultReference() {
|
public static Config defaultReference() {
|
||||||
return ReferenceHolder.referenceConfig;
|
try {
|
||||||
|
return ReferenceHolder.referenceConfig;
|
||||||
|
} catch (ExceptionInInitializerError e) {
|
||||||
|
throw ConfigUtil.extractInitializerError(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.typesafe.config.impl;
|
package com.typesafe.config.impl;
|
||||||
|
|
||||||
|
import com.typesafe.config.ConfigException;
|
||||||
|
|
||||||
|
|
||||||
/** This is public just for the "config" package to use, don't touch it */
|
/** This is public just for the "config" package to use, don't touch it */
|
||||||
final public class ConfigUtil {
|
final public class ConfigUtil {
|
||||||
@ -118,4 +120,14 @@ final public class ConfigUtil {
|
|||||||
}
|
}
|
||||||
return s.substring(start, end);
|
return s.substring(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** This is public just for the "config" package to use, don't touch it! */
|
||||||
|
public static ConfigException extractInitializerError(ExceptionInInitializerError e) {
|
||||||
|
Throwable cause = e.getCause();
|
||||||
|
if (cause != null && cause instanceof ConfigException) {
|
||||||
|
return (ConfigException) cause;
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user