Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in environment variable reading behavior #802

Open
ilinandrii opened this issue Jan 16, 2024 · 2 comments
Open

Regression in environment variable reading behavior #802

ilinandrii opened this issue Jan 16, 2024 · 2 comments

Comments

@ilinandrii
Copy link

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
Copy link
Author

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.

@ekrich
Copy link
Contributor

ekrich commented Jan 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants