config icon indicating copy to clipboard operation
config copied to clipboard

Regression in environment variable reading behavior

Open ilinandrii opened this issue 1 year ago • 2 comments

Starting from 1.4.1 this code behaves differently then previously:

ConfigFactory.systemEnvironmentOverrides().withFallback(ConfigFactory.systemProperties)

Here's the simple test. Run this application with environment variable VARIABLE set to any String

import com.typesafe.config.ConfigFactory

//VARIABLE=test

object Test extends App {
  val env = ConfigFactory.systemEnvironmentOverrides().withFallback(ConfigFactory.systemProperties)
  println(env.getString("VARIABLE"))
}

implementation('com.typesafe:config:1.4.0') Output:

> Task :Test.main()
test

implementation('com.typesafe:config:1.4.1') Output

> Task :Test.main() FAILED
Exception in thread "main" com.typesafe.config.ConfigException$Missing: system properties: No configuration setting found for key 'VARIABLE'
	at com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:157)
	at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:175)
	at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:189)
	at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:194)
	at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:251)
	at Test$.delayedEndpoint$Test$1(Test.scala:6)
	at Test$delayedInit$body.apply(Test.scala:3)
	at scala.Function0.apply$mcV$sp(Function0.scala:42)
	at scala.Function0.apply$mcV$sp$(Function0.scala:42)
	at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
	at scala.App.$anonfun$main$1(App.scala:98)
	at scala.App.$anonfun$main$1$adapted(App.scala:98)
	at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:575)
	at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:573)
	at scala.collection.AbstractIterable.foreach(Iterable.scala:933)
	at scala.App.main(App.scala:98)
	at scala.App.main$(App.scala:96)
	at Test$.main(Test.scala:3)
	at Test.main(Test.scala)

I've printed config as well and made a text search for VARIABLE and indeed no such variable there.

ilinandrii avatar Jan 16 '24 18:01 ilinandrii

Seems like this fix breaks my code and is done intentionally. If you're not going to revert this change you can close this issue and I'll make adjustment to my code. Anyway FYI I may not be only one who relied on previous behavior.

ilinandrii avatar Jan 16 '24 18:01 ilinandrii

If you are in pure Scala environment you could consider trying out ekrich/sconfig. Most of the changes and fixes have not been ported across but that or other bugs could be an issue. There is a package change but scalafix to help out.

ekrich avatar Jan 16 '24 20:01 ekrich