From c992add265775c33026a662e67188889eeabec4e Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Wed, 6 Nov 2024 12:02:09 +0000 Subject: [PATCH] Avoid possible concurrency issues with RestClientsConfig.RestClientKeysProvider.KEYS in build time --- .../config/AbstractRestClientConfigBuilder.java | 16 ++++++++++++++-- .../config/RestClientsBuildTimeConfig.java | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/AbstractRestClientConfigBuilder.java b/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/AbstractRestClientConfigBuilder.java index 1f0d37b0ca1551..26faff8777282a 100644 --- a/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/AbstractRestClientConfigBuilder.java +++ b/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/AbstractRestClientConfigBuilder.java @@ -53,9 +53,19 @@ public abstract class AbstractRestClientConfigBuilder implements ConfigBuilder { private static final String REST_CLIENT_PREFIX = "quarkus.rest-client."; + private final boolean runtime; + + public AbstractRestClientConfigBuilder() { + this.runtime = true; + RestClientsConfig.RestClientKeysProvider.KEYS.clear(); + } + + public AbstractRestClientConfigBuilder(boolean runtime) { + this.runtime = runtime; + } + @Override public SmallRyeConfigBuilder configBuilder(final SmallRyeConfigBuilder builder) { - RestClientsConfig.RestClientKeysProvider.KEYS.clear(); List restClients = getRestClients(); Map quarkusFallbacks = new HashMap<>(); @@ -63,7 +73,9 @@ public SmallRyeConfigBuilder configBuilder(final SmallRyeConfigBuilder builder) // relocates [All Combinations] -> quarkus.rest-client."FQN".* Map relocates = new HashMap<>(); for (RegisteredRestClient restClient : restClients) { - RestClientsConfig.RestClientKeysProvider.KEYS.add(restClient.getFullName()); + if (runtime) { + RestClientsConfig.RestClientKeysProvider.KEYS.add(restClient.getFullName()); + } // FQN -> Simple Name String quotedFullName = "\"" + restClient.getFullName() + "\""; diff --git a/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/RestClientsBuildTimeConfig.java b/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/RestClientsBuildTimeConfig.java index 192c41fd1c72dc..47df726193404d 100644 --- a/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/RestClientsBuildTimeConfig.java +++ b/extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/RestClientsBuildTimeConfig.java @@ -143,7 +143,7 @@ private ConfigSource getDefaultsSource() { .withCustomizers(new SmallRyeConfigBuilderCustomizer() { @Override public void configBuilder(final SmallRyeConfigBuilder builder) { - new AbstractRestClientConfigBuilder() { + new AbstractRestClientConfigBuilder(false) { @Override public List getRestClients() { return restClients;