Skip to content

Commit

Permalink
fix destroy NullPointerException and doOverrideIfNecessary (#8683)
Browse files Browse the repository at this point in the history
IllegalStateException
  • Loading branch information
zrlw committed Sep 12, 2021
1 parent 55dec92 commit e63a7be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Expand Up @@ -25,6 +25,7 @@
import org.apache.dubbo.config.context.ConfigManager;

import java.util.Collection;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

Expand Down Expand Up @@ -112,6 +113,15 @@ public static String getApplication() {
return application == null ? getName() : application;
}

@Deprecated
public static String tryGetApplication() {
if (application != null) {
return application;
}
Optional<ApplicationConfig> appCfgOptional = getConfigManager().getApplication();
return appCfgOptional.isPresent() ? appCfgOptional.get().getName() : null;
}

// Currently used by UT.
@Deprecated
public static void setApplication(String application) {
Expand Down
Expand Up @@ -572,8 +572,13 @@ public void destroy() {
}
bounds.clear();

String application = ApplicationModel.tryGetApplication();
if (application == null) {
// already removed
return;
}
ExtensionLoader.getExtensionLoader(GovernanceRuleRepository.class).getDefaultExtension()
.removeListener(ApplicationModel.getApplication() + CONFIGURATORS_SUFFIX, providerConfigurationListener);
.removeListener(application + CONFIGURATORS_SUFFIX, providerConfigurationListener);
}

@Override
Expand Down Expand Up @@ -688,7 +693,8 @@ public synchronized void doOverrideIfNecessary() {
return;
}
//The current, may have been merged many times
URL currentUrl = exporter.getInvoker().getUrl();
Invoker<?> exporterInvoker = exporter.getInvoker();
URL currentUrl = exporterInvoker == null ? null : exporterInvoker.getUrl();
//Merged with this configuration
URL newUrl = getConfiguredInvokerUrl(configurators, originUrl);
newUrl = getConfiguredInvokerUrl(providerConfigurationListener.getConfigurators(), newUrl);
Expand Down

0 comments on commit e63a7be

Please sign in to comment.