From 098b7d5b12e527910e97268215b112bd1af2f6cf Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Thu, 27 Nov 2025 16:08:52 +0100 Subject: [PATCH] Log warning instead of throwing exception on multiple build calls (#1847) Log warning instead of throwing IllegalStateException on multiple build calls - Change `build()` to log a warning instead of throwing an exception on subsequent calls. - Change `buildKtor()` to log a warning instead of throwing an exception on subsequent calls. --- .../at/bitfire/davdroid/network/HttpClientBuilder.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/network/HttpClientBuilder.kt b/app/src/main/kotlin/at/bitfire/davdroid/network/HttpClientBuilder.kt index 50ec066de..87bd93a2e 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/network/HttpClientBuilder.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/network/HttpClientBuilder.kt @@ -190,7 +190,7 @@ class HttpClientBuilder @Inject constructor( /** * Builds an [OkHttpClient] with the configured settings. * - * [build] or [buildKtor] must be called only once because multiple calls indicate this wrong usage pattern: + * [build] or [buildKtor] is usually called only once because multiple calls indicate this wrong usage pattern: * * ``` * val builder = HttpClientBuilder(/*injected*/) @@ -200,12 +200,10 @@ class HttpClientBuilder @Inject constructor( * * However in this case the configuration of `client1` is still in `builder` and would be reused for `client2`, * which is usually not desired. - * - * @throws IllegalStateException on second and later calls */ fun build(): OkHttpClient { if (alreadyBuilt) - throw IllegalStateException("build() must only be called once; use Provider") + logger.warning("build() should only be called once; use Provider instead") val builder = OkHttpClient.Builder() configureOkHttp(builder) @@ -384,7 +382,7 @@ class HttpClientBuilder @Inject constructor( @MustBeClosed fun buildKtor(): HttpClient { if (alreadyBuilt) - throw IllegalStateException("build() must only be called once; use Provider") + logger.warning("buildKtor() should only be called once; use Provider instead") val client = HttpClient(OkHttp) { // Ktor-level configuration here