Hi,
There is an issue that I'm facing after upgrade to 0.23.1 version, I don't face the issue when using 0.22.0.
Basically, if I have the code below, and the env variables are empty i.e MAIL_USER=, an error is thrown when using the native image.
application.properties
quarkus.mailer.username=${MAIL_USER}
quarkus.mailer.password=${MAIL_PASSWORD}
log:
java.util.NoSuchElementException: Property MAIL_USER not found
at io.smallrye.config.SmallRyeConfig.propertyNotFound(SmallRyeConfig.java:221)
at io.smallrye.config.SmallRyeConfig.getValue(SmallRyeConfig.java:112)
at io.quarkus.runtime.configuration.ConfigExpander.accept(ConfigExpander.java:55)
at io.quarkus.runtime.configuration.ConfigExpander.accept(ConfigExpander.java:15)
at org.wildfly.common.expression.ExpressionNode.emit(ExpressionNode.java:42)
at org.wildfly.common.expression.Expression.evaluateException(Expression.java:75)
at org.wildfly.common.expression.Expression.evaluate(Expression.java:89)
at io.quarkus.runtime.configuration.ExpandingConfigSource.expandValue(ExpandingConfigSource.java:76)
at io.quarkus.runtime.configuration.ExpandingConfigSource.expand(ExpandingConfigSource.java:48)
at io.quarkus.runtime.configuration.ExpandingConfigSource.getValue(ExpandingConfigSource.java:44)
at io.quarkus.runtime.configuration.DeploymentProfileConfigSource.getValue(DeploymentProfileConfigSource.java:57)
at io.smallrye.config.SmallRyeConfig.getOptionalValue(SmallRyeConfig.java:136)
at io.smallrye.config.SmallRyeConfig.getOptionalValue(SmallRyeConfig.java:131)
at io.quarkus.runtime.configuration.ConfigUtils.getOptionalValue(ConfigUtils.java:92)
at io.quarkus.runtime.generated.RunTimeConfig.parseKey_mailer_username(RunTimeConfig.zig:26910)
at io.quarkus.runtime.generated.RunTimeConfig.parseKey_mailer(RunTimeConfig.zig:11247)
at io.quarkus.runtime.generated.RunTimeConfig.parseKey(RunTimeConfig.zig:14679)
at io.quarkus.runtime.generated.RunTimeConfig.getRunTimeConfiguration(RunTimeConfig.zig:32470)
at io.quarkus.runner.ApplicationImpl1.doStart(ApplicationImpl1.zig:125)
at io.quarkus.runtime.Application.start(Application.java:93)
at io.quarkus.runtime.Application.run(Application.java:213)
at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:34)
Exception in thread "main" java.lang.RuntimeException: Failed to start quarkus
at io.quarkus.runner.ApplicationImpl1.doStart(ApplicationImpl1.zig:259)
at io.quarkus.runtime.Application.start(Application.java:93)
at io.quarkus.runtime.Application.run(Application.java:213)
at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:34)
Caused by: java.util.NoSuchElementException: Property MAIL_USER not found
at io.smallrye.config.SmallRyeConfig.propertyNotFound(SmallRyeConfig.java:221)
at io.smallrye.config.SmallRyeConfig.getValue(SmallRyeConfig.java:112)
at io.quarkus.runtime.configuration.ConfigExpander.accept(ConfigExpander.java:55)
at io.quarkus.runtime.configuration.ConfigExpander.accept(ConfigExpander.java:15)
at org.wildfly.common.expression.ExpressionNode.emit(ExpressionNode.java:42)
at org.wildfly.common.expression.Expression.evaluateException(Expression.java:75)
at org.wildfly.common.expression.Expression.evaluate(Expression.java:89)
at io.quarkus.runtime.configuration.ExpandingConfigSource.expandValue(ExpandingConfigSource.java:76)
at io.quarkus.runtime.configuration.ExpandingConfigSource.expand(ExpandingConfigSource.java:48)
at io.quarkus.runtime.configuration.ExpandingConfigSource.getValue(ExpandingConfigSource.java:44)
at io.quarkus.runtime.configuration.DeploymentProfileConfigSource.getValue(DeploymentProfileConfigSource.java:57)
at io.smallrye.config.SmallRyeConfig.getOptionalValue(SmallRyeConfig.java:136)
at io.smallrye.config.SmallRyeConfig.getOptionalValue(SmallRyeConfig.java:131)
at io.quarkus.runtime.configuration.ConfigUtils.getOptionalValue(ConfigUtils.java:92)
at io.quarkus.runtime.generated.RunTimeConfig.parseKey_mailer_username(RunTimeConfig.zig:26910)
at io.quarkus.runtime.generated.RunTimeConfig.parseKey_mailer(RunTimeConfig.zig:11247)
at io.quarkus.runtime.generated.RunTimeConfig.parseKey(RunTimeConfig.zig:14679)
at io.quarkus.runtime.generated.RunTimeConfig.getRunTimeConfiguration(RunTimeConfig.zig:32470)
at io.quarkus.runner.ApplicationImpl1.doStart(ApplicationImpl1.zig:125)
... 3 more
related to https://github.com/quarkusio/quarkus/issues/4123? @dmlloyd @gsmet
No, it's a new problem, but working as designed: by specifying the environment variable as empty (rather than undefining it), you're explicitly saying that you want the value to be empty, which will cause a failure. Since you're expanding the property with no default, you're also causing the property to be undefined as well.
So, first you need to change your config like this:
quarkus.mailer.username=${MAIL_USER:}
quarkus.mailer.password=${MAIL_PASSWORD:}
This says "if the property is empty or missing, expand to an empty string".
Now, there is a good argument to say that when expanding a variable, empty values should expand into empty strings implicitly. However the problem is that the config infrastructure deliberately does not attempt to make a distinction between explicitly empty or empty-because-it-is-missing. Thus if we were to make such a change, it would mean that it would be impossible to cause a failure when a referenced property is not present.
If this whole thing just stinks to you, another approach would be to remove these two properties and environment variables from your configuration, and instead use the "QUARKUS_MAILER_USERNAME" and "QUARKUS_MAILER_PASSWORD" environment variables directly.
Thanks @dmlloyd for chiming in with a good explanation.
"QUARKUS_MAILER_USERNAME" and "QUARKUS_MAILER_PASSWORD" environment variables directly.
Indeed, this is a good alternative solution since mailer configurations can be overridden at runtime.
So should this be closed as invalid (working as expected)?
Sure, unless someone has a good argument that the current behavior is wrong.
Agreed, I made the mailer this way actually. username and password are runtime as IMHO it's a runtime thing.
Please reopen if you disagree with the invalidity.
Agree, thanks for the explanation @dmlloyd !
Most helpful comment
No, it's a new problem, but working as designed: by specifying the environment variable as empty (rather than undefining it), you're explicitly saying that you want the value to be empty, which will cause a failure. Since you're expanding the property with no default, you're also causing the property to be undefined as well.
So, first you need to change your config like this:
This says "if the property is empty or missing, expand to an empty string".
Now, there is a good argument to say that when expanding a variable, empty values should expand into empty strings implicitly. However the problem is that the config infrastructure deliberately does not attempt to make a distinction between explicitly empty or empty-because-it-is-missing. Thus if we were to make such a change, it would mean that it would be impossible to cause a failure when a referenced property is not present.
If this whole thing just stinks to you, another approach would be to remove these two properties and environment variables from your configuration, and instead use the "QUARKUS_MAILER_USERNAME" and "QUARKUS_MAILER_PASSWORD" environment variables directly.