The reason for the exception is that Scene.DnDGesture.handleExitEnter
is called reentrantly.
Here's an example of what may have happened:
1. We enter handleExitEnter(), and compute j = newTargets.size() - 1
(in our example, perhaps j = 2)
2. We enter the loop and call Event.fireEvent()
3. The event handler calls GtkDnDClipboard.mimesFromSystem()
4. In the native implementation:
a. We call dnd_target_get_mimes()
b. which calls dnd_target_receive_data()
c. which calls gtk_main_iteration()
5. While we are blocked at gtk_main_iteration(), GTK processes another event
6. Let's suppose GTK is processing a drag-motion event:
a. We enter process_dnd_target_drag_motion()
b. which calls View.notifyDragOver
7. We now enter handleExitEvent() reentrantly, and complete the nested
call with:
currentTargets.clear();
currentTargets.addAll(newTargets);
newTargets.clear();
8. Eventually the outer call to Event.fireEvent() returns, and resumes
with j == 2
9. But now newTargets.size() == 0
10. newTargets.get(2) throws exactly: Index 2 out of bounds for length 0