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

ConfigRetriever uses data type double for Integer env values #110

Open
MarWestermann opened this issue Feb 5, 2020 · 1 comment
Open
Labels

Comments

@MarWestermann
Copy link

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 pushed a commit to MarWestermann/vertx-config that referenced this issue Feb 5, 2020
@gaol
Copy link
Member

gaol commented Mar 24, 2020

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

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

No branches or pull requests

2 participants