Skip to content

Commit 9b14481

Browse files
Flanker-MSFTFlanker-MSFT
authored andcommitted
Fix possible index out of bounds exception when select resource
1 parent f1dae81 commit 9b14481

File tree

1 file changed

+2
-2
lines changed
  • PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common/component

1 file changed

+2
-2
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common/component/TreeUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,10 @@ public static boolean underTypeGroups(@Nonnull TreePath path) {
266266

267267
public static void selectResourceNode(@Nonnull JTree tree, @Nonnull AzComponent resource) {
268268
final DefaultMutableTreeNode r = (DefaultMutableTreeNode) tree.getModel().getRoot();
269-
DefaultMutableTreeNode root = ((DefaultMutableTreeNode) r.getChildAt(1)); // apps root
269+
DefaultMutableTreeNode root = r.getChildCount() > 1 ? ((DefaultMutableTreeNode) r.getChildAt(1)) : null; // apps root
270270
if (resource instanceof Favorite) {
271271
resource = ((Favorite) resource).getResource();
272-
root = (DefaultMutableTreeNode) r.getChildAt(0); // favorite root
272+
root = r.getChildCount() > 0 ? (DefaultMutableTreeNode) r.getFirstChild() : null; // favorite root
273273
}
274274
if (Objects.nonNull(resource)) {
275275
selectResourceNode(tree, resource, root);

0 commit comments

Comments
 (0)