Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 127975

Summary: Exception thrown when disposing caret
Product: [Eclipse Project] Platform Reporter: Florian Priester <fwp>
Component: SWTAssignee: Niraj Modi <niraj.modi>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: niraj.modi, remy.suen
Version: 3.2Keywords: triaged
Target Milestone: 4.13 M1   
Hardware: PC   
OS: All   
See Also: https://git.eclipse.org/r/145585
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=68da4318d8869a0a7957ca4663aefb7954a6a578
https://git.eclipse.org/r/145591
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=de243af25cf849e9e332d82f0dc5e4b655e99107
Whiteboard:
Attachments:
Description Flags
TestSnippet. none

Description Florian Priester CLA 2006-02-15 02:04:03 EST
SWT-win32, v3224

When running the code below, the following exception is thrown:

Exception in thread "main" org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:3349)
	at org.eclipse.swt.SWT.error(SWT.java:3272)
	at org.eclipse.swt.SWT.error(SWT.java:3243)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:432)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:327)
	at org.eclipse.swt.widgets.Canvas.getCaret(Canvas.java:108)
	at org.eclipse.swt.widgets.Caret.releaseParent(Caret.java:283)
	at org.eclipse.swt.widgets.Widget.release(Widget.java:748)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:412)
	at CaretDisposeTest.main(CaretDisposeTest.java:...)

---

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

public class CaretDisposeTest {
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Caret caret = new Caret(shell, SWT.NONE);
    shell.setCaret(null);
    shell.dispose();
    caret.dispose();
    display.dispose();
  }
}
Comment 1 Remy Suen CLA 2009-09-03 20:18:48 EDT
Confirmed to be broken with I20090811-0800 on Linux/gtk+.

Exception in thread "main" org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:3887)
	at org.eclipse.swt.SWT.error(SWT.java:3802)
	at org.eclipse.swt.SWT.error(SWT.java:3773)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:452)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:390)
	at org.eclipse.swt.widgets.Canvas.getCaret(Canvas.java:124)
	at org.eclipse.swt.widgets.Caret.releaseParent(Caret.java:296)
	at org.eclipse.swt.widgets.Widget.release(Widget.java:1062)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:448)
	at Main.main(Main.java:217)
Comment 2 Bogdan Gheorghe CLA 2009-09-30 17:19:57 EDT
This is still a problem - we should be handling the caret disposal better. As a workaround, you can add a dispose listener and handle the caret disposal there.
Comment 3 Niraj Modi CLA 2017-07-14 07:47:01 EDT
(In reply to Bogdan Gheorghe from comment #2)
> This is still a problem - we should be handling the caret disposal better.
> As a workaround, you can add a dispose listener and handle the caret
> disposal there.

Tested on Win7, can reproduce the problem with snippet in comment 0, will investigate.
Comment 4 Niraj Modi CLA 2019-07-05 05:15:45 EDT
I have a possible solution for this bug fix, targeting for 4.13
Comment 5 Eclipse Genie CLA 2019-07-08 01:52:32 EDT
New Gerrit change created: https://git.eclipse.org/r/145585
Comment 7 Niraj Modi CLA 2019-07-08 02:22:05 EDT
Created attachment 279188 [details]
TestSnippet.

Tested with attached snippet on my Ubuntu setup and can reproduce the problem on GTK as well. Since the Carent.releaseParent() logic is same on all platform, so IMO this problem must also be seen on Cocoa.
Comment 8 Eclipse Genie CLA 2019-07-08 02:31:47 EDT
New Gerrit change created: https://git.eclipse.org/r/145591
Comment 10 Niraj Modi CLA 2019-07-08 07:34:41 EDT
Resolving now.
Comment 11 Niraj Modi CLA 2019-07-09 05:31:02 EDT
Verified using Build id: I20190708-1800 on Win7.