Repository: quarkusio/quarkus
Issue: REST client considers the wrong environment variable for `quarkus.rest-client."config-key".url`

### Describe the bug

I have set an environment `QUARKUS_REST_CLIENT__MY_CLIENT__URL` variable set which is supposed to override the `quarkus.rest-client."my-client".url` at runtime. The `quarkus.rest-client."my-client".url` has a fallback setting in `application.properties`.

### Expected behavior

The REST client uses the URL from the environment variable. This works in Quarkus 2.11.1, but does not work in Quarkus 2.12.2. 

### Actual behavior

This happens in Quarkus 2.12.2:

The REST client ignores the environment variablee and uses the fallback setting in `application.properties`. When I change the name of the environment variable to `QUARKUS_REST_CLIENT_MY_CLIENT_URL`  (note the missing extra underscores for the `"`) then the value of the environment variable is used.

In Quarkus 2.11.1, everything works as expected.

### How to Reproduce?

_No response_

### Output of `uname -a` or `ver`

Darwin <redacted> 20.6.0 Darwin Kernel Version 20.6.0: Tue Feb 22 21:10:41 PST 2022; root:xnu-7195.141.26~1/RELEASE_X86_64 x86_64

### Output of `java -version`

openjdk version "11.0.11" 2021-04-20 OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9) OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode)

### GraalVM version (if different from Java)

_No response_

### Quarkus version or git rev

2.12.2

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

Apache Maven 3.8.6

### Additional information

_No response_

Changed files:
core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java

diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java
index 210d5f34d1c..4fc98dae8fe 100644
--- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java
+++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java
@@ -5,6 +5,8 @@
 import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_PROFILE;
 import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_PROFILE_PARENT;
 import static io.smallrye.config.SmallRyeConfigBuilder.META_INF_MICROPROFILE_CONFIG_PROPERTIES;
+import static java.lang.Integer.MAX_VALUE;
+import static java.lang.Integer.MIN_VALUE;
 
 import java.io.IOException;
 import java.net.URL;
@@ -13,7 +15,6 @@
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -39,13 +40,13 @@
 import io.smallrye.config.EnvConfigSource;
 import io.smallrye.config.FallbackConfigSourceInterceptor;
 import io.smallrye.config.KeyMap;
-import io.smallrye.config.KeyMapBackedConfigSource;
 import io.smallrye.config.Priorities;
 import io.smallrye.config.ProfileConfigSourceInterceptor;
 import io.smallrye.config.RelocateConfigSourceInterceptor;
 import io.smallrye.config.SmallRyeConfig;
 import io.smallrye.config.SmallRyeConfigBuilder;
 import io.smallrye.config.SysPropConfigSource;
+import io.smallrye.config.common.MapBackedConfigSource;
 import io.smallrye.config.common.utils.ConfigSourceUtil;
 
 /**
@@ -115,10 +116,8 @@ public static SmallRyeConfigBuilder configBuilder(final boolean runTime, final b
             builder.addDiscoveredValidator();
             builder.withDefaultValue(UUID_KEY, UUID.randomUUID().toString());
             builder.withSources(new DotEnvConfigSourceProvider());
-            builder.withSources(
-                    new DefaultsConfigSource(loadBuildTimeRunTimeValues(), "BuildTime RunTime Fixed", Integer.MAX_VALUE));
-            builder.withSources(
-                    new DefaultsConfigSource(loadRunTimeDefaultValues(), "RunTime Defaults", Integer.MIN_VALUE + 100));
+            builder.withSources(new DefaultsConfigSource(loadBuildTimeRunTimeValues(), "BuildTime RunTime Fixed", MAX_VALUE));
+            builder.withSources(new DefaultsConfigSource(loadRunTimeDefaultValues(), "RunTime Defaults", MIN_VALUE + 100));
         } else {
             List<ConfigSource> sources = new ArrayList<>();
             sources.addAll(classPathSources(META_INF_MICROPROFILE_CONFIG_PROPERTIES, classLoader));
@@ -384,43 +383,35 @@ public Set<String> getPropertyNames() {
         }
     }
 
-    static class DefaultsConfigSource extends KeyMapBackedConfigSource {
+    static class DefaultsConfigSource extends MapBackedConfigSource {
         private final KeyMap<String> wildcards;
-        private final Set<String> propertyNames;
 
         public DefaultsConfigSource(final Map<String, String> properties, final String name, final int ordinal) {
-            super(name, ordinal, propertiesToKeyMap(properties));
+            // Defaults may contain wildcards, but we don't want to expose them in getPropertyNames, so we need to filter them
+            super(name, filterWildcards(properties), ordinal);
             this.wildcards = new KeyMap<>();
-            this.propertyNames = new HashSet<>();
             for (Map.Entry<String, String> entry : properties.entrySet()) {
                 if (entry.getKey().contains("*")) {
                     this.wildcards.findOrAdd(entry.getKey()).putRootValue(entry.getValue());
-                } else {
-                    this.propertyNames.add(entry.getKey());
                 }
             }
         }
 
-        @Override
-        public Set<String> getPropertyNames() {
-            return propertyNames;
-        }
-
         @Override
         public String getValue(final String propertyName) {
             String value = super.getValue(propertyName);
             return value == null ? wildcards.findRootValue(propertyName) : value;
         }
 
-        private static KeyMap<String> propertiesToKeyMap(final Map<String, String> properties) {
-            KeyMap<String> keyMap = new KeyMap<>();
+        private static Map<String, String> filterWildcards(final Map<String, String> properties) {
+            Map<String, String> filtered = new HashMap<>();
             for (Map.Entry<String, String> entry : properties.entrySet()) {
                 if (entry.getKey().contains("*")) {
                     continue;
                 }
-                keyMap.findOrAdd(entry.getKey()).putRootValue(entry.getValue());
+                filtered.put(entry.getKey(), entry.getValue());
             }
-            return keyMap;
+            return filtered;
         }
     }