vertx-config icon indicating copy to clipboard operation
vertx-config copied to clipboard

ConfigRetriever uses data type double for Integer env values

Open MarWestermann opened this issue 5 years ago • 1 comments

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 avatar Feb 05 '20 15:02 MarWestermann

@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);

gaol avatar Mar 24 '20 05:03 gaol