Skip to content
Permalink
Browse files
8267392: ENTER key press on editable TableView throws NPE
Reviewed-by: fastegal, aghaisas
  • Loading branch information
Maran23 authored and aghaisas committed May 21, 2021
1 parent 111bac4 commit 5843910333ebdbc4ea14033461e980b0d0692ca8
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -891,15 +891,20 @@ protected void activate(KeyEvent e) {
if (fm == null) return;

TablePositionBase<TC> cell = getFocusedCell();
sm.select(cell.getRow(), cell.getTableColumn());
TC tableColumn = cell.getTableColumn();
sm.select(cell.getRow(), tableColumn);
setAnchor(cell);

if (tableColumn == null) {
return;
}

// check if we are editable
boolean isEditable = isControlEditable() && cell.getTableColumn().isEditable();
boolean isEditable = isControlEditable() && tableColumn.isEditable();

// edit this row also
if (isEditable && cell.getRow() >= 0) {
editCell(cell.getRow(), cell.getTableColumn());
editCell(cell.getRow(), tableColumn);
e.consume();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -63,6 +63,7 @@
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -184,6 +185,19 @@ private boolean isAnchor(int row, int col) {
* Tests for row-based single selection
**************************************************************************/

@Test
public void testEnterOnFocusedRowDoesNotThrowNPE() {
tableView.setEditable(true);

assertNull(tableView.getSelectionModel().getSelectedItem());
assertEquals(0, tableView.getFocusModel().getFocusedCell().getRow());

// Fire an ENTER event on the focused row. This should not throw a NPE!
keyboard.doKeyPress(KeyCode.ENTER);

assertNotNull(tableView.getSelectionModel().getSelectedItem());
}

@Test public void testDownArrowChangesSelection() {
sm.clearAndSelect(0);
keyboard.doDownArrowPress();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -62,6 +62,7 @@
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -242,6 +243,19 @@ private int getItemCount() {
* Tests for row-based single selection
**************************************************************************/

@Test
public void testEnterOnFocusedRowDoesNotThrowNPE() {
tableView.setEditable(true);

assertNull(tableView.getSelectionModel().getSelectedItem());
assertEquals(0, tableView.getFocusModel().getFocusedCell().getRow());

// Fire an ENTER event on the focused row. This should not throw a NPE!
keyboard.doKeyPress(KeyCode.ENTER);

assertNotNull(tableView.getSelectionModel().getSelectedItem());
}

@Test public void testDownArrowChangesSelection() {
sm.clearAndSelect(0);
keyboard.doDownArrowPress();

1 comment on commit 5843910

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 5843910 May 21, 2021

Please sign in to comment.