From 8b9959d39b8bc2fa9298d5acee62905bd2d94172 Mon Sep 17 00:00:00 2001 From: Abhay Date: Sun, 27 Apr 2025 10:43:12 +0000 Subject: [PATCH 1/2] added the detailed instructions for the setProviderAndWait Signed-off-by: Abhay --- README.md | 14 ++++++++++++-- .../java/dev/openfeature/sdk/OpenFeatureAPI.java | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 22d85bd2d..429d2ae44 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,12 @@ public void example(){ // configure a provider OpenFeatureAPI api = OpenFeatureAPI.getInstance(); - api.setProviderAndWait(new InMemoryProvider(myFlags)); + try { + api.setProviderAndWait(new InMemoryProvider(myFlags)); + } catch (Exception e) { + // handle initialization failure + e.printStackTrace(); + } // create a client Client client = api.getClient(); @@ -149,7 +154,12 @@ To register a provider in a blocking manner to ensure it is ready before further ```java OpenFeatureAPI api = OpenFeatureAPI.getInstance(); - api.setProviderAndWait(new MyProvider()); + try { + api.setProviderAndWait(new MyProvider()); + } catch (Exception e) { + // handle initialization failure + e.printStackTrace(); + } ``` #### Asynchronous diff --git a/src/main/java/dev/openfeature/sdk/OpenFeatureAPI.java b/src/main/java/dev/openfeature/sdk/OpenFeatureAPI.java index bd60cc78a..e60302e82 100644 --- a/src/main/java/dev/openfeature/sdk/OpenFeatureAPI.java +++ b/src/main/java/dev/openfeature/sdk/OpenFeatureAPI.java @@ -207,7 +207,13 @@ public void setProvider(String domain, FeatureProvider provider) { } /** - * Set the default provider and wait for initialization to finish. + * Sets the default provider and waits for its initialization to complete. + *

+ * Note: If the provider fails during initialization, an {@link OpenFeatureError} will be thrown. + * It is recommended to wrap this call in a try-catch block to handle potential initialization failures gracefully. + * + * @param provider the {@link FeatureProvider} to set as the default. + * @throws OpenFeatureError if the provider fails during initialization. */ public void setProviderAndWait(FeatureProvider provider) throws OpenFeatureError { try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) { @@ -223,9 +229,13 @@ public void setProviderAndWait(FeatureProvider provider) throws OpenFeatureError /** * Add a provider for a domain and wait for initialization to finish. - * + *

+ * Note: If the provider fails during initialization, an {@link OpenFeatureError} will be thrown. + * It is recommended to wrap this call in a try-catch block to handle potential initialization failures gracefully. + * * @param domain The domain to bind the provider to. * @param provider The provider to set. + * @throws OpenFeatureError if the provider fails during initialization. */ public void setProviderAndWait(String domain, FeatureProvider provider) throws OpenFeatureError { try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) { From bc96bfe0709dda27098f2f511868d34ffd527bf8 Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Mon, 28 Apr 2025 13:08:56 +0200 Subject: [PATCH 2/2] fixup: checkstyle issues Signed-off-by: Simon Schrottner --- src/main/java/dev/openfeature/sdk/OpenFeatureAPI.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/openfeature/sdk/OpenFeatureAPI.java b/src/main/java/dev/openfeature/sdk/OpenFeatureAPI.java index e60302e82..66d40736f 100644 --- a/src/main/java/dev/openfeature/sdk/OpenFeatureAPI.java +++ b/src/main/java/dev/openfeature/sdk/OpenFeatureAPI.java @@ -208,8 +208,8 @@ public void setProvider(String domain, FeatureProvider provider) { /** * Sets the default provider and waits for its initialization to complete. - *

- * Note: If the provider fails during initialization, an {@link OpenFeatureError} will be thrown. + * + *

Note: If the provider fails during initialization, an {@link OpenFeatureError} will be thrown. * It is recommended to wrap this call in a try-catch block to handle potential initialization failures gracefully. * * @param provider the {@link FeatureProvider} to set as the default. @@ -229,10 +229,10 @@ public void setProviderAndWait(FeatureProvider provider) throws OpenFeatureError /** * Add a provider for a domain and wait for initialization to finish. - *

- * Note: If the provider fails during initialization, an {@link OpenFeatureError} will be thrown. + * + *

Note: If the provider fails during initialization, an {@link OpenFeatureError} will be thrown. * It is recommended to wrap this call in a try-catch block to handle potential initialization failures gracefully. - * + * * @param domain The domain to bind the provider to. * @param provider The provider to set. * @throws OpenFeatureError if the provider fails during initialization.