Skip to content

Commit

Permalink
#6846: Uncaught Exception java.lang.IndexOutOfBoundsException: Index …
Browse files Browse the repository at this point in the history
…0 out of bounds for length 0
  • Loading branch information
wangmingliang-ms committed Sep 21, 2022
1 parent eb033d6 commit fabd785
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
import com.intellij.openapi.project.Project;
import com.intellij.ui.TitledSeparator;
import com.microsoft.azure.toolkit.ide.appservice.model.AppServiceConfig;
import com.microsoft.azure.toolkit.intellij.legacy.appservice.platform.RuntimeComboBox;
import com.microsoft.azure.toolkit.intellij.common.AzureArtifact;
import com.microsoft.azure.toolkit.intellij.common.AzureArtifactComboBox;
import com.microsoft.azure.toolkit.intellij.common.AzureArtifactManager;
import com.microsoft.azure.toolkit.intellij.common.AzureFormPanel;
import com.microsoft.azure.toolkit.intellij.legacy.appservice.platform.RuntimeComboBox;
import com.microsoft.azure.toolkit.lib.appservice.model.Runtime;
import com.microsoft.azure.toolkit.lib.auth.AzureAccount;
import com.microsoft.azure.toolkit.lib.common.form.AzureFormInput;
import com.microsoft.azure.toolkit.lib.common.model.Subscription;
import lombok.SneakyThrows;
import org.apache.commons.compress.utils.FileNameUtils;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.Nonnull;
import javax.swing.*;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
Expand All @@ -29,7 +29,6 @@
import java.util.Objects;
import java.util.function.Supplier;

import static com.microsoft.azure.toolkit.lib.Azure.az;
import static com.microsoft.azuretools.utils.WebAppUtils.isSupportedArtifactType;

public class AppServiceInfoBasicPanel<T extends AppServiceConfig> extends JPanel implements AzureFormPanel<T> {
Expand All @@ -50,18 +49,15 @@ public class AppServiceInfoBasicPanel<T extends AppServiceConfig> extends JPanel
private JLabel lblName;
private JLabel lblPlatform;

private Subscription subscription;

public AppServiceInfoBasicPanel(final Project project, final Supplier<? extends T> defaultConfigSupplier) {
public AppServiceInfoBasicPanel(final Project project, @Nonnull final Subscription subscription, final Supplier<? extends T> defaultConfigSupplier) {
super();
this.project = project;
this.supplier = defaultConfigSupplier;
$$$setupUI$$$(); // tell IntelliJ to call createUIComponents() here.
this.init();
this.init(subscription);
}

private void init() {
this.subscription = az(AzureAccount.class).account().getSelectedSubscriptions().get(0);
private void init(Subscription subscription) {
this.textName.setRequired(true);
this.textName.setSubscription(subscription);
this.selectorRuntime.setRequired(true);
Expand Down Expand Up @@ -104,6 +100,7 @@ public T getValue() {
public void setValue(final T config) {
this.config = config;
this.textName.setValue(config.getName());
this.textName.setSubscription(config.getSubscription());
this.selectorRuntime.setValue(config.getRuntime());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@

import com.intellij.openapi.project.Project;
import com.microsoft.azure.toolkit.ide.appservice.webapp.model.WebAppConfig;
import com.microsoft.azure.toolkit.intellij.legacy.appservice.AppServiceInfoBasicPanel;
import com.microsoft.azure.toolkit.intellij.common.AzureFormPanel;
import com.microsoft.azure.toolkit.intellij.common.ConfigDialog;
import com.microsoft.azure.toolkit.intellij.legacy.appservice.AppServiceInfoBasicPanel;
import com.microsoft.azure.toolkit.lib.appservice.model.PricingTier;
import com.microsoft.azure.toolkit.lib.auth.AzureAccount;
import com.microsoft.azure.toolkit.lib.auth.IAccountActions;
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
import com.microsoft.azure.toolkit.lib.common.model.Subscription;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.List;

import static com.microsoft.azure.toolkit.intellij.common.AzureBundle.message;
import static com.microsoft.azure.toolkit.lib.Azure.az;

public class WebAppCreationDialog extends ConfigDialog<WebAppConfig> {
private static final PricingTier DEFAULT_PRICING_TIER = PricingTier.BASIC_B2;
Expand Down Expand Up @@ -58,8 +64,12 @@ protected String getDialogTitle() {
private void createUIComponents() {
// TODO: place custom component creation code here
advancedForm = new WebAppConfigFormPanelAdvance(project);

basicForm = new AppServiceInfoBasicPanel(project, () -> WebAppConfig.getWebAppDefaultConfig(project.getName()));
final List<Subscription> selectedSubscriptions = az(AzureAccount.class).account().getSelectedSubscriptions();
if (selectedSubscriptions.isEmpty()) {
this.close();
throw new AzureToolkitRuntimeException("there are no subscriptions selected in your account.", IAccountActions.SELECT_SUBS);
}
basicForm = new AppServiceInfoBasicPanel(project, selectedSubscriptions.get(0), () -> WebAppConfig.getWebAppDefaultConfig(project.getName()));
basicForm.setDeploymentVisible(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import com.microsoft.azure.toolkit.lib.Azure;
import com.microsoft.azure.toolkit.lib.auth.Account;
import com.microsoft.azure.toolkit.lib.auth.AzureAccount;
import com.microsoft.azure.toolkit.lib.auth.IAccountActions;
import com.microsoft.azure.toolkit.lib.common.bundle.AzureString;
import com.microsoft.azure.toolkit.lib.common.event.AzureEventBus;
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
import com.microsoft.azure.toolkit.lib.common.model.Subscription;
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
import org.apache.commons.collections4.CollectionUtils;

import javax.annotation.Nonnull;
import java.util.List;
Expand Down Expand Up @@ -48,7 +49,9 @@ public String getName() {
private void selectSubscription() {
final Account account = Azure.az(AzureAccount.class).account();
final List<Subscription> subscriptions = account.getSubscriptions();
assert CollectionUtils.isNotEmpty(subscriptions) : "there are no subscriptions in your account";
if (subscriptions.isEmpty()) {
throw new AzureToolkitRuntimeException("there are no subscriptions in your account", IAccountActions.TRY_AZURE, IAccountActions.SELECT_SUBS);
}
List<Subscription> selectedSubscriptions = account.getSelectedSubscriptions();
if (selectedSubscriptions.isEmpty()) {
account.setSelectedSubscriptions(List.of(subscriptions.get(0).getId()));
Expand Down

0 comments on commit fabd785

Please sign in to comment.