Commit 20cf0ee2 authored by Florian Schäfer's avatar Florian Schäfer

Make sure, the `WikiSearchTextResultList` doesn't throw an `IndexOutOfBoundsException`

The issue was reported as https://josm.openstreetmap.de/ticket/16840 and should now be resolved.
parent 553ded71
Pipeline #33030260 passed with stages
in 10 minutes and 44 seconds
......@@ -12,13 +12,17 @@ abstract class WikiSearchTextResultListPanel<T> extends SearchTextResultListPane
Executors.newSingleThreadScheduledExecutor(Utils.newThreadFactory("wikipedia-search-%d", Thread.NORM_PRIORITY)));
public T getSelectedItem() {
final T selected = lsResult.getSelectedValue();
if (selected != null) {
return selected;
} else if (!lsResultModel.isEmpty()) {
return lsResultModel.getElementAt(0);
} else {
return null;
synchronized (lsResultModel) {
final int idx = lsResult.getSelectedIndex();
final T selected = idx < lsResultModel.getSize() && idx >= 0 ? lsResultModel.getElementAt(idx) : null;
if (selected != null) {
return selected;
} else if (!lsResultModel.isEmpty()) {
return lsResultModel.getElementAt(0);
} else {
return null;
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment