Skip to content

Commit

Permalink
fix: NPE on named provider init/shutdown (#595)
Browse files Browse the repository at this point in the history
* fix NPE on named provider init
* add condition for not calling shutdown on null old provider

Signed-off-by: liran2000 <liran2000@gmail.com>
  • Loading branch information
liran2000 authored Sep 7, 2023
1 parent a2e4894 commit d063bf2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/dev/openfeature/sdk/ProviderRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,15 @@ private void initializeProvider(FeatureProvider newProvider,
}

private void shutDownOld(FeatureProvider oldProvider,Consumer<FeatureProvider> afterShutdown) {
if (!isProviderRegistered(oldProvider)) {
if (oldProvider != null && !isProviderRegistered(oldProvider)) {
shutdownProvider(oldProvider);
afterShutdown.accept(oldProvider);
}
}

private boolean isProviderRegistered(FeatureProvider oldProvider) {
return this.providers.containsValue(oldProvider) || this.defaultProvider.get().equals(oldProvider);
return oldProvider != null && (this.providers.containsValue(oldProvider)
|| this.defaultProvider.get().equals(oldProvider));
}

private void shutdownProvider(FeatureProvider provider) {
Expand Down

0 comments on commit d063bf2

Please sign in to comment.