vertx-config
vertx-config copied to clipboard
ConfigRetriever uses data type double for Integer env values
Version
3.7.1
Context
An Environment variable like PORT=8080 is converted to 8080.0 (double) in config json.
Do you have a reproducer?
Add Environment Variable PORT = 8080 to your system.
val configRetriever = ConfigRetriever.create(vertx)
configRetriever.rxGetConfig().flatMap { configJson ->
configJson.getInteger("PORT") // Exception: double cannot be casted to Integer
}
Extra
The cause of the issue is in class io.vertx.config.spi.utils.JsonObjectHelper. There in convert method a number value would always be converted to a double but a check is missing if it is a pure Integer.
@MarWestermann doesn't JsonObject.getInteger() convert to Integer in case of double ?
The following test in both 3.7.1 and master passed:
--- a/vertx-config/src/test/java/io/vertx/config/impl/spi/EnvVariablesConfigStoreWithMockEnvTest.java
+++ b/vertx-config/src/test/java/io/vertx/config/impl/spi/EnvVariablesConfigStoreWithMockEnvTest.java
@@ -71,9 +71,11 @@ public class EnvVariablesConfigStoreWithMockEnvTest extends ConfigStoreTestBase
AtomicBoolean done = new AtomicBoolean();
env.set("name", "12345678901234567891");
+ env.set("port", "8080");
retriever.getConfig(ar -> {
assertThat(ar.succeeded()).isTrue();
+ assertThat(ar.result().getInteger("port")).isEqualTo(8080);
// Converted value, totally wrong ;-)
assertThat(ar.result().getInteger("name")).isEqualTo(2147483647);
done.set(true);