Skip to content

Commit a628e0f

Browse files
committed
VarsPane: add some defensive checks
Various things can go wrong when individual script languages do not support certain features. In particular, we really need the Bindings#keySet() method to work, or else we cannot introspect the variables.
1 parent 8577b71 commit a628e0f

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/main/java/org/scijava/ui/swing/script/VarsPane.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ public VarsPane(final Context context, final ScriptREPL repl) {
7676
public void actionPerformed(final ActionEvent e) {
7777
final ScriptLanguage lang = (ScriptLanguage) langBox.getSelectedItem();
7878
if (lang == repl.getInterpreter().getLanguage()) return; // no change
79-
repl.lang(lang.getLanguageName());
79+
try {
80+
repl.lang(lang.getLanguageName());
81+
}
82+
catch (final RuntimeException exc) {
83+
// Something went wrong...
84+
// TODO: Issue the exception to the log via the LogService.
85+
}
8086
update();
8187
}
8288
});
@@ -124,8 +130,14 @@ private class VarsTableModel extends AbstractTableModel {
124130

125131
public void update() {
126132
varNames.clear();
127-
varNames.addAll(repl.getInterpreter().getBindings().keySet());
128-
Collections.sort(varNames);
133+
try {
134+
varNames.addAll(repl.getInterpreter().getBindings().keySet());
135+
Collections.sort(varNames);
136+
}
137+
catch (final RuntimeException exc) {
138+
// Something went wrong. Leave the variables list empty.
139+
// TODO: Issue the exception to the log via the LogService.
140+
}
129141
fireTableDataChanged();
130142
}
131143

@@ -160,6 +172,7 @@ public int getRowCount() {
160172

161173
@Override
162174
public Object getValueAt(final int rowIndex, final int columnIndex) {
175+
if (rowIndex >= varNames.size()) return null;
163176
final String varName = varNames.get(rowIndex);
164177
switch (columnIndex) {
165178
case 0:

0 commit comments

Comments
 (0)