Skip to content

Commit 08c425c

Browse files
authored
Fix NPE while refreshing deployment slots (#4564)
* Fix NPE while refreshing deployment slots * Mark parameters as not null
1 parent fa81440 commit 08c425c

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/WebAppDeployMvpViewSlim.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@
3333
public interface WebAppDeployMvpViewSlim extends MvpView {
3434
void fillWebApps(@NotNull List<ResourceEx<WebApp>> webAppLists, final String defaultWebAppId);
3535

36-
void fillDeploymentSlots(@NotNull List<DeploymentSlot> slots);
36+
void fillDeploymentSlots(@NotNull List<DeploymentSlot> slots, final ResourceEx<WebApp> selectedWebApp);
3737
}

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/WebAppDeployViewPresenterSlim.java

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,40 @@
2727
import com.microsoft.azuretools.core.mvp.model.webapp.AzureWebAppMvpModel;
2828
import com.microsoft.azuretools.core.mvp.ui.base.MvpPresenter;
2929
import com.microsoft.tooling.msservices.components.DefaultLoader;
30-
import org.apache.commons.lang3.StringUtils;
30+
import org.apache.commons.lang3.exception.ExceptionUtils;
3131
import rx.Observable;
32+
import rx.Subscription;
3233

34+
import java.io.InterruptedIOException;
3335
import java.util.List;
3436

3537
public class WebAppDeployViewPresenterSlim<V extends WebAppDeployMvpViewSlim> extends MvpPresenter<V> {
3638

3739
private static final String CANNOT_LIST_WEB_APP = "Failed to list web apps.";
3840
private static final String CANNOT_GET_DEPLOYMENT_SLOTS = "Failed to get the deployment slots.";
3941

40-
public void onLoadDeploymentSlots(final String subscriptionId, final String webAppId) {
41-
if (StringUtils.isEmpty(subscriptionId) || StringUtils.isEmpty(webAppId)) {
42-
return;
43-
}
44-
Observable.fromCallable(() -> AzureWebAppMvpModel.getInstance().getDeploymentSlots(subscriptionId, webAppId))
45-
.subscribeOn(getSchedulerProvider().io())
46-
.subscribe(slots -> DefaultLoader.getIdeHelper().invokeLater(() -> {
47-
if (isViewDetached()) {
48-
return;
49-
}
50-
getMvpView().fillDeploymentSlots(slots);
51-
}), e -> errorHandler(CANNOT_GET_DEPLOYMENT_SLOTS, (Exception) e));
52-
}
42+
private Subscription loadSlotsSubscription;
43+
private Subscription loadWebAppsSubscription;
5344

5445
public void onLoadDeploymentSlots(final ResourceEx<WebApp> selectedWebApp) {
5546
if (selectedWebApp == null) {
5647
return;
5748
}
58-
onLoadDeploymentSlots(selectedWebApp.getSubscriptionId(), selectedWebApp.getResource().id());
49+
unsubscribeSubscription(loadSlotsSubscription);
50+
loadSlotsSubscription = Observable.fromCallable(() -> AzureWebAppMvpModel.getInstance().getDeploymentSlots(
51+
selectedWebApp.getSubscriptionId(), selectedWebApp.getResource().id()))
52+
.subscribeOn(getSchedulerProvider().io())
53+
.subscribe(slots -> DefaultLoader.getIdeHelper().invokeLater(() -> {
54+
if (isViewDetached()) {
55+
return;
56+
}
57+
getMvpView().fillDeploymentSlots(slots, selectedWebApp);
58+
}), e -> errorHandler(CANNOT_GET_DEPLOYMENT_SLOTS, (Exception) e));
5959
}
6060

6161
public void loadWebApps(boolean forceRefresh, String defaultWebAppId) {
62-
Observable.fromCallable(() -> {
62+
unsubscribeSubscription(loadWebAppsSubscription);
63+
loadWebAppsSubscription = Observable.fromCallable(() -> {
6364
List<ResourceEx<WebApp>> result = AzureWebAppMvpModel.getInstance().listAllWebApps(forceRefresh);
6465
return result;
6566
}
@@ -73,7 +74,17 @@ public void loadWebApps(boolean forceRefresh, String defaultWebAppId) {
7374
}), e -> errorHandler(CANNOT_LIST_WEB_APP, (Exception) e));
7475
}
7576

77+
private void unsubscribeSubscription(Subscription subscription) {
78+
if (subscription != null && !subscription.isUnsubscribed()) {
79+
subscription.unsubscribe();
80+
}
81+
}
82+
7683
private void errorHandler(String msg, Exception e) {
84+
if (ExceptionUtils.getRootCause(e) instanceof InterruptedIOException) {
85+
// Swallow interrupted exception caused by unsubscribe
86+
return;
87+
}
7788
DefaultLoader.getIdeHelper().invokeLater(() -> {
7889
if (isViewDetached()) {
7990
return;

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/webapp/webappconfig/slimui/WebAppSlimSettingPanel.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,23 +268,22 @@ public synchronized void fillWebApps(List<ResourceEx<WebApp>> webAppLists, final
268268
}
269269

270270
@Override
271-
public synchronized void fillDeploymentSlots(List<DeploymentSlot> slotList) {
271+
public synchronized void fillDeploymentSlots(List<DeploymentSlot> slotList, @NotNull final ResourceEx<WebApp> selectedWebApp) {
272272
cbxSlotName.removeAllItems();
273273
cbxSlotConfigurationSource.removeAllItems();
274274

275275
cbxSlotConfigurationSource.addItem(Constants.DO_NOT_CLONE_SLOT_CONFIGURATION);
276-
cbxSlotConfigurationSource.addItem(getSelectedWebApp().getResource().name());
276+
cbxSlotConfigurationSource.addItem(selectedWebApp.getResource().name());
277277
slotList.stream().filter(slot -> slot != null).forEach(slot -> {
278278
cbxSlotName.addItem(slot.name());
279279
cbxSlotConfigurationSource.addItem(slot.name());
280-
if (Comparing.equal(slot.name(), webAppConfiguration.getSlotName())) {
280+
if (StringUtils.equals(slot.name(), webAppConfiguration.getSlotName())) {
281281
cbxSlotName.setSelectedItem(slot.name());
282282
}
283-
if (Comparing.equal(slot.name(), webAppConfiguration.getNewSlotConfigurationSource())) {
283+
if (StringUtils.equals(slot.name(), webAppConfiguration.getNewSlotConfigurationSource())) {
284284
cbxSlotConfigurationSource.setSelectedItem(slot.name());
285285
}
286286
});
287-
288287
boolean existDeploymentSlot = slotList.size() > 0;
289288
lblNewSlot.setVisible(!existDeploymentSlot);
290289
cbxSlotName.setVisible(existDeploymentSlot);

0 commit comments

Comments
 (0)