wellcomecollection / platform

Wellcome Collection Digital Platform
https://developers.wellcomecollection.org/
MIT License
48 stars 10 forks source link

Inconsistent behaviour for integer Config variables #3824

Closed warrd closed 7 months ago

warrd commented 5 years ago

Summary

When an integer is specified in a typesafe config file (application.conf) it is parsed as an Int when specified directly, but as a String when from an environment variable.

Required action

This is potentially a bug in the typesafe config library itself.

The wellcome-typesafe-app should be updated to handle this inconsistency, specifically in the EnrichConfig object (required / get / getOrElse).

Further info

The id_minter has crashed in production due to this issue:

Exception in thread "main" java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Integer (java.lang.String and java.lang.Integer are in module java.base of loader 'bootstrap')
at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:103)
at uk.ac.wellcome.platform.idminter.config.builders.RDSBuilder$.buildDB(RDSBuilder.scala:10)
at uk.ac.wellcome.platform.idminter.Main$.$anonfun$new$1(Main.scala:34)
at uk.ac.wellcome.typesafe.WellcomeTypesafeApp.runWithConfig(WellcomeTypesafeApp.scala:8)
at uk.ac.wellcome.typesafe.WellcomeTypesafeApp.runWithConfig$(WellcomeTypesafeApp.scala:6)
at uk.ac.wellcome.platform.idminter.Main$.runWithConfig(Main.scala:21)
at uk.ac.wellcome.platform.idminter.Main$.delayedEndpoint$uk$ac$wellcome$platform$idminter$Main$1(Main.scala:22)
at uk.ac.wellcome.platform.idminter.Main$delayedInit$body.apply(Main.scala:21)
at scala.Function0.apply$mcV$sp(Function0.scala:39)
at scala.Function0.apply$mcV$sp$(Function0.scala:39)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
at scala.App.$anonfun$main$1$adapted(App.scala:80)
at scala.collection.immutable.List.foreach(List.scala:392)
at scala.App.main(App.scala:80)
at scala.App.main$(App.scala:78)
at uk.ac.wellcome.platform.idminter.Main$.main(Main.scala:21)
at uk.ac.wellcome.platform.idminter.Main.main(Main.scala)

This console output illustrates the behaviour for environment variables:

$ cat pipeline/id_minter/src/main/resources/application.conf 
...
aws.rds.maxConnections=${?max_connections}
...

$ export max_connections=8

$ sbt id_minter/console

scala> val config  = com.typesafe.config.ConfigFactory.load()

scala> config.getAnyRef("aws.rds.maxConnections")
res0: Object = 8

scala> config.getAnyRef("aws.rds.maxConnections").getClass
res1: Class[_ <: Object] = class java.lang.String

scala> config.getAnyRef("aws.rds.maxConnections").asInstanceOf[Int]
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
kenoir commented 7 months ago

Closing as outdated.