org.eclipse.rap icon indicating copy to clipboard operation
org.eclipse.rap copied to clipboard

Infinite loop in RAPDragTracker

Open SOlECtiT opened this issue 2 years ago • 0 comments

Incident: In the processing of RAPDragTracker in LightweightSystem of org.eclipse.rap.draw2d/src/org/eclipse/draw2d/LightweightSystem.java, if Canvas is forcibly terminated, processing within RAPDragTracker will loop infinitely.

Cause: If Canvas is forcibly terminated and display.isDisposed becomes true, there is no timing to exit the while loop.

Code Snippet:

while (tracking && !cancelled) {
    if (display != null && !display.isDisposed()) {
        display.syncExec(new Runnable() {
            public void run() {
                if (canvas.isDisposed()) {
                    tracking = false;
                    cancelled = true;
                    return;
                }
                Event ev = new Event();
                //...
            }
        });
    } else {
        break;
    }
}

Thread Dump:

"Worker-6" #62 prio=5 os_prio=0 tid=0x00007f4dfc2a7800 nid=0x3d42 runnable [0x00007f4dcd14d000]
   java.lang.Thread.State: RUNNABLE
    at org.eclipse.draw2d.LightweightSystem$RAPDragTracker$1.run(LightweightSystem.java:500)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

Proposed Solution: To avoid an infinite loop, the while loop should be exited if display.isDisposed becomes true. If display.isDisposed() becomes true, it is possible to avoid an endless loop by exiting the while loop.

if (display != null && !display.isDisposed()) {
 (omitted)
} else {
 break;
}

SOlECtiT avatar Sep 11 '23 06:09 SOlECtiT