Skip to content

Commit

Permalink
Fix NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
aghaisas committed Apr 7, 2020
1 parent 560ef17 commit dbb5603
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Expand Up @@ -650,15 +650,19 @@ private void processRightKey(KeyEvent ke) {

private void showMenu(Menu menu) {
menu.show();
// request focus on the first item of the submenu after it is shown
ContextMenuContent cmContent = (ContextMenuContent)submenu.getSkin().getNode();
if (cmContent != null) {
if (cmContent.itemsContainer.getChildren().size() > 0) {
cmContent.itemsContainer.getChildren().get(0).requestFocus();
cmContent.currentFocusedIndex = 0;
} else {
cmContent.requestFocus();
}

// if there is a submenu
if (submenu != null) {
// request focus on the first item of the submenu after it is shown
ContextMenuContent cmContent = (ContextMenuContent)submenu.getSkin().getNode();
if (cmContent != null) {
if (cmContent.itemsContainer.getChildren().size() > 0) {
cmContent.itemsContainer.getChildren().get(0).requestFocus();
cmContent.currentFocusedIndex = 0;
} else {
cmContent.requestFocus();
}
}
}
}

Expand Down
Expand Up @@ -452,6 +452,22 @@ private ContextMenu createContextMenuAndShowSubMenu() {
subMenuItem1, focusedItem);
}

@Test public void test_emptySubMenu_rightKeyDoesNothing() {
Menu testMenu = new Menu("Menu1");
ContextMenu testCM = new ContextMenu();

testCM.getItems().addAll(testMenu);
testCM.show(anchorBtn, Side.RIGHT, 0, 0);
assertNotNull(getShowingMenuContent(testCM));

// Go to testMenu
pressDownKey(testCM);

// testMenu does not have any subMenu - try to open it
// this used to casue NPE - fixed in JDK-8241710
pressRightKey(testCM);
}

@Test public void test_navigateSubMenu_leftKeyClosesSubMenu() {
ContextMenu cm = createContextMenuAndShowSubMenu();

Expand Down

0 comments on commit dbb5603

Please sign in to comment.