Bug 363789 - Widget is disposed in Accessible#getCaretOffset
Summary: Widget is disposed in Accessible#getCaretOffset
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.7.1   Edit
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-15 04:40 EST by Marcel CLA
Modified: 2021-11-12 11:35 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcel CLA 2011-11-15 04:40:52 EST
Build Identifier: 

We get error reports from our customers with the stacktrace below.
Unfortunately we have no scenario to reproduce. To some users, it happens only once, others suffer every several hours.
We're using SWT 3.7.1 right now, it also happened with 3.6.x. Our application is plain Java+SWT (no RCP).
It happens on Windows XP, Vista and 7.
Do you have any idea/recommendation?

Reproducible: Sometimes

Steps to Reproduce:
Trace:
org.eclipse.swt.SWTException: Widget is disposed
        at org.eclipse.swt.SWT.error(SWT.java:4282)
        at org.eclipse.swt.SWT.error(SWT.java:4197)
        at org.eclipse.swt.SWT.error(SWT.java:4168)
        at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
        at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
        at org.eclipse.swt.custom.StyledText.getCaretOffset(StyledText.java:3647)
        at org.eclipse.swt.custom.StyledText$12.getCaretOffset(StyledText.java:6344)
        at org.eclipse.swt.accessibility.Accessible.getCaretOffset(Accessible.java:4808)
        at org.eclipse.swt.accessibility.Accessible.get_caretOffset(Accessible.java:4099)
        at org.eclipse.swt.accessibility.Accessible$10.method5(Accessible.java:458)
        at org.eclipse.swt.internal.ole.win32.COMObject.callback5(COMObject.java:110)
        at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
        at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2531)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3752)
Comment 1 Carolyn MacLeod CLA 2011-11-15 16:37:02 EST
What accessibility tool are your customers using?
Screen reader? Magnifier?

Is this happening when the StyledText loses focus, or maybe when the editor associated with the StyledText is closed, or perhaps when the user closes your application?
Comment 2 Marcel CLA 2011-11-16 03:16:21 EST
From the error reports, we have no more details. I've ask one of the users about usage scenarios and screen reader.
What is a bit special is that during the last month, only users having set a Spanish locale are affected (es_AR, es_ES, es_MX, es_CO) - I'll check whether there is something suspicious in our Spanish translation...
Comment 3 Marcel CLA 2011-11-21 11:29:33 EST
One of the users uses a screenreader. I'll try to find out which exactly.
Comment 4 Carolyn MacLeod CLA 2011-11-21 12:59:23 EST
For some reason, a screen reader (or other accessible technology program) is asking for a StyledText's caret offset after the StyledText is disposed.
I can't see how this could happen in our code - we call Dispose() on the StyledText's accessible object before we mark the StyledText's state as DISPOSED.
So the screen reader (or AT) should know that the StyledText is gone, and it should not be calling in to it any more. Perhaps there's a Spanish-speaking screen reader that has a reference counting bug and it is not playing by the rules? Very strange.
Comment 5 Marcel CLA 2011-11-22 02:33:15 EST
I just got the following information from our customer:
"The software is Job Access With Speech (JAWS) Versión 12 . 0. 1158 "
Comment 6 Carolyn MacLeod CLA 2011-11-22 12:26:47 EST
Thanks. JAWS is a very well-known, and pretty solid, screen reader.
There was a JAWS fix recently that did help some Eclipse applications work better with JAWS. Details are in bug 344335. It does NOT sound like the same problem, because that problem was crashing JAWS. However, if your user is willing to try upgrading to the very latest JAWS (13.0.527 or later) then it might help.

Another thing that might help is to start Eclipse from the command line, adding:
-vmargs -Dorg.eclipse.swt.accessibility.UseIA2=false
If that helps, then it can be added to the eclipse.ini file.

If neither of those suggestions helps, then I really need to somehow replicate the problem here, so that I can debug it, and if necessary I can ask a JAWS developer to look at it with me.
Comment 7 Marcel CLA 2011-12-06 10:47:09 EST
Hi again
I could reproduce a similar issue (slightly different stacktrace, see below).
I used JAWS 13 on Windows 7.
Steps:
Put Focus into StyledText
Close window (JAWS is still talking about the text field)
Open Window again, textfield becomes visible again but more or less immediately, it crashes:

Caused by: org.eclipse.swt.SWTException: Widget is disposed
        at org.eclipse.swt.SWT.error(SWT.java:4282)
        at org.eclipse.swt.SWT.error(SWT.java:4197)
        at org.eclipse.swt.SWT.error(SWT.java:4168)
        at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
        at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
        at org.eclipse.swt.widgets.Control.isEnabled(Control.java:1810)
        at org.eclipse.swt.custom.StyledText$15.getState(StyledText.java:6788)
        at org.eclipse.swt.accessibility.Accessible.get_accState(Accessible.java:2506)
        at org.eclipse.swt.accessibility.Accessible$1.method14(Accessible.java:159)
        at org.eclipse.swt.internal.ole.win32.COMObject.callback14(COMObject.java:191)
        at org.eclipse.swt.internal.win32.OS.SetFocus(Native Method)
        at org.eclipse.swt.widgets.Control.forceFocus(Control.java:1098)
        at org.eclipse.swt.widgets.Control.setFocus(Control.java:3303)
        at org.eclipse.swt.widgets.Composite.setFocus(Composite.java:1040)
        at org.eclipse.swt.widgets.Composite.setFocus(Composite.java:1038)
        at org.eclipse.swt.widgets.Composite.setFocus(Composite.java:1038)
        at org.eclipse.swt.widgets.Composite.setFocus(Composite.java:1038)
        at org.eclipse.swt.widgets.Composite.setFocus(Composite.java:1038)
Comment 8 Carolyn MacLeod CLA 2011-12-06 12:22:35 EST
I can't make this happen with JAWS 13.0.527 and Windows XP.
I will try installing JAWS on a Windows 7 machine, but first, please tell me exactly what you were doing.
I opened a java editor (StyledText) and got JAWS to start reading all of the java code in it by typing INS+down arrow. Then I closed the editor and reopened it.
I did this maybe 10 times and did not crash. Twice, JAWS did not immediately start reading anything in the reopened editor, even when I typed down arrow. On those 2 occasions, INS+down arrow did reconnect JAWS to the reopened editor.
But there were no crashes.
Also, note that I was using mouse double-click to reopen the closed editor.
If this is not all exactly what you were doing, then perhaps that is why I am not getting the crash. (Or maybe it's Windows XP vs. Windows 7, but I'd like to be sure we are both doing the same steps first).
Comment 9 Marcel CLA 2011-12-07 07:43:20 EST
I did not try with eclipse. The application is Wuala (from www.wuala.com), however I can reproduce with the snippet (below, quite ugly, sorry) and get the following error:

Exception in thread "main" org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed)
	at org.eclipse.swt.SWT.error(SWT.java:4282)
	at org.eclipse.swt.SWT.error(SWT.java:4197)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
	at JAWSSnippet.main(JAWSSnippet.java:46)
Caused by: org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:4282)
	at org.eclipse.swt.SWT.error(SWT.java:4197)
	at org.eclipse.swt.SWT.error(SWT.java:4168)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
	at org.eclipse.swt.widgets.Control.isEnabled(Control.java:1810)
	at org.eclipse.swt.custom.StyledText$15.getState(StyledText.java:6788)
	at org.eclipse.swt.accessibility.Accessible.get_accState(Accessible.java:2506)
	at org.eclipse.swt.accessibility.Accessible$1.method14(Accessible.java:159)
	at org.eclipse.swt.internal.ole.win32.COMObject.callback14(COMObject.java:191)
	at org.eclipse.swt.internal.win32.OS.SetFocus(Native Method)
	at org.eclipse.swt.widgets.Control.forceFocus(Control.java:1098)
	at org.eclipse.swt.widgets.Control.setTabItemFocus(Control.java:3650)
	at org.eclipse.swt.widgets.Composite.setTabGroupFocus(Composite.java:1145)
	at org.eclipse.swt.widgets.Control.traverseGroup(Control.java:4293)
	at org.eclipse.swt.widgets.Shell.open(Shell.java:1248)
	at JAWSSnippet.openShell(JAWSSnippet.java:61)
	at JAWSSnippet.access$0(JAWSSnippet.java:51)
	at JAWSSnippet$1$1.run(JAWSSnippet.java:34)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	... 3 more
Comment 10 Marcel CLA 2011-12-07 07:43:35 EST
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;


public class JAWSSnippet {

	public static void main(String[] args) {
		
		final Display disp= Display.getDefault();
		
		final Shell shell= openShell(disp);
		boolean go= true;
		while(!disp.isDisposed()) {
			if (shell.isDisposed() && go) {
				go= false;
				new Thread() {
					@Override
					public void run() {
						try {
							Thread.sleep(2000);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						disp.asyncExec(new Runnable() {
							public void run() {
								Shell shell2 = openShell(disp);
								shell2.addDisposeListener(new DisposeListener() {
									
									public void widgetDisposed(DisposeEvent e) {
										disp.dispose();
									}
								});
							}
						});
					};
				}.start();
			}
			disp.readAndDispatch();
		}
		
	}
	
	private static Shell openShell(Display disp) {
		System.out.println("JAWSSnippet.openShell()");
		Shell shell= new Shell(disp);
		shell.setLayout(new GridLayout(2, false));
		Label label= new Label(shell, SWT.NONE);
		label.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false));
		label.setText("Some label: ");
		final StyledText text= new StyledText(shell, SWT.NONE);
		text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

		shell.open();
		
		shell.getDisplay().timerExec(20, new Runnable() {

            public void run() {
            	if (!text.isDisposed()) {
                    text.forceFocus();
                } else {
                	System.out.println("JAWSSnippet - disposed");
                }
            }
        });
		return shell;
	}

}
Comment 11 Marcel CLA 2011-12-07 07:45:18 EST
When running the snippet, close the shell - it will get reopened.
When JAWS is running, the error happens. Without JAWS, the second shell opens fine.
Comment 12 Michael Whapples CLA 2020-05-20 05:03:19 EDT
I have noticed similar exceptions in a project I am working on which uses SWT for the UI. We originally were using SWT version 3.105.3 but I have also tried updating to SWT 3.114.0 and still get the exception. I notice it with both NVDA and narrator screen readers.
Comment 13 Michael Whapples CLA 2020-05-20 05:19:53 EDT
I should have commented this is running on Windows10. NVDA is version 2020.1.
Comment 14 Michael Whapples CLA 2020-05-20 05:55:17 EDT
I have submitted a bug report to the NVDA project https://github.com/nvaccess/nvda/issues/11156
There it has been said that In particular one of the comments suggests that SWT may not be following the COM rules:
prevent further remote calls from reaching the object.