From 5ab6cd5fc4d625a7ffc51455274f0707158473fd Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Sat, 26 Sep 2015 10:11:11 -0400 Subject: [PATCH] Prevent AIOOBE in error table If the error checker updates the table between the click and invocation of the click event listener, selection will be cleared and click index will be -1. Checking if the index is valid before using it. --- app/src/processing/app/ui/ErrorTable.java | 36 +++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/app/src/processing/app/ui/ErrorTable.java b/app/src/processing/app/ui/ErrorTable.java index a38216409..9dc7df067 100644 --- a/app/src/processing/app/ui/ErrorTable.java +++ b/app/src/processing/app/ui/ErrorTable.java @@ -105,25 +105,25 @@ public class ErrorTable extends JTable { // } addMouseListener(new MouseAdapter() { - @Override - synchronized public void mouseClicked(MouseEvent e) { - try { - int row = ((ErrorTable) e.getSource()).getSelectedRow(); - if (row >= 0 && row < getRowCount()) { - Object data = getModel().getValueAt(row, DATA_COLUMN); - int clickCount = e.getClickCount(); - if (clickCount == 1) { - editor.errorTableClick(data); - } else if (clickCount > 1) { - editor.errorTableDoubleClick(data); - } + @Override + synchronized public void mouseClicked(MouseEvent e) { + try { + int row = ((ErrorTable) e.getSource()).getSelectedRow(); + if (row >= 0 && row < getRowCount()) { + Object data = getModel().getValueAt(row, DATA_COLUMN); + int clickCount = e.getClickCount(); + if (clickCount == 1) { + editor.errorTableClick(data); + } else if (clickCount > 1) { + editor.errorTableDoubleClick(data); + } // editor.getErrorChecker().scrollToErrorLine(row); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - }); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + }); /* addMouseMotionListener(new MouseMotionAdapter() {