Skip to content

Commit 7a58c2e

Browse files
authored
Merge pull request lightbend#464 from camullen/master
ConfigFactory.invalidateCaches() also resets environment variables cache
2 parents 180d66b + 0659ab5 commit 7a58c2e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

config/src/main/java/com/typesafe/config/ConfigFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ public static void invalidateCaches() {
496496
// We rely on this having the side effect that it drops
497497
// all caches
498498
ConfigImpl.reloadSystemPropertiesConfig();
499+
ConfigImpl.reloadEnvVariablesConfig();
499500
}
500501

501502
/**

config/src/main/java/com/typesafe/config/impl/ConfigImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ private static AbstractConfigObject loadEnvVariables() {
339339
}
340340

341341
private static class EnvVariablesHolder {
342-
static final AbstractConfigObject envVariables = loadEnvVariables();
342+
static volatile AbstractConfigObject envVariables = loadEnvVariables();
343343
}
344344

345345
static AbstractConfigObject envVariablesAsConfigObject() {
@@ -354,6 +354,12 @@ public static Config envVariablesAsConfig() {
354354
return envVariablesAsConfigObject().toConfig();
355355
}
356356

357+
public static void reloadEnvVariablesConfig() {
358+
// ConfigFactory.invalidateCaches() relies on this having the side
359+
// effect that it drops all caches
360+
EnvVariablesHolder.envVariables = loadEnvVariables();
361+
}
362+
357363
public static Config defaultReference(final ClassLoader loader) {
358364
return computeCachedConfig(loader, "defaultReference", new Callable<Config>() {
359365
@Override

0 commit comments

Comments
 (0)