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

Bug 69650

Summary: Focus lost when focused widget is disposed
Product: [Eclipse Project] Platform Reporter: Travis Hume <travis.hume>
Component: SWTAssignee: Ian Pun <ipun>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: akurtakov, arunkumar.thondapu, billy.biggs, cocoakevin, daniel_megert, douglas.pollock, eclipse, ericwill, gheorghe, john.arthorne, markus.kell.r, Michael.Valenta
Version: 3.0   
Target Milestone: 4.7 M3   
Hardware: PC   
OS: Linux-GTK   
See Also: https://git.eclipse.org/r/80517
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=52881b02b736327002428947c3a54bd5fb1b6761
https://git.eclipse.org/r/80748
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=03e505a39be2165463f88264099ee8921b2bb263
https://git.eclipse.org/r/80853
https://git.eclipse.org/r/81008
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=67e18320e2682697b68f564901b6459633fc9938
Whiteboard:
Attachments:
Description Flags
Proposed patch none

Description Travis Hume CLA 2004-07-08 13:48:09 EDT
Open synchronize view
perform an update
Hit F12 to goto Editor

Nothing happens.  Ctrl+T to open type doesn't work.  I have to use the mouse to
focus the editor and then keybinding start working again.

I hate the mouse :)
Comment 1 Veronika Irvine CLA 2004-08-13 11:59:30 EDT
Can't recreate this.  Unclear what you mean by "perform an update".

Moving to UI team.
Comment 2 Douglas Pollock CLA 2004-08-13 14:22:14 EDT
There is no focus control when this problem happens.  I believe this is an SWT 
problem.  I don't believe that the focus control should ever be null if the 
workbench window has focus. 
 
I found that to recreate the problem it helps to have existing changes.  Then 
"Update" or "Override and Update" on all changes.  The tree gets destroyed when 
the update completes, and is replaced with some kind of text widget giving you 
helpful advice about no changes.  At this point, the focus control becomes 
null. 
 
However, if I create changes while my workspace is already around, it doesn't 
seem to happen all the time.  I'm not sure why. 
Comment 3 Veronika Irvine CLA 2004-08-17 11:56:19 EDT
Is this Linux GTK or Linux Motif?
Comment 4 Travis Hume CLA 2004-08-17 15:04:15 EDT
Linux GTK+
Comment 5 Veronika Irvine CLA 2004-08-19 10:41:03 EDT
Felipe, can you find out why the focus control is null?
Comment 6 Felipe Heidrich CLA 2004-08-20 15:07:43 EDT
I can't reproduce this bug. Doug, can you help me ?
Comment 7 Felipe Heidrich CLA 2004-08-26 17:50:56 EDT
Please let me know what is your linux, your desktop, and your window manager.
Comment 8 Travis Hume CLA 2004-08-26 19:21:13 EDT
Gentoo linux kernel v2.6.8.1
gtk+ v2.4.4
glibc-2.3.3

Gnome 2.6.2

Window manager: metacity v2.8.1

This is my machine, but I've also seen this behaviour on our pairing stations
with run mandrake 9.3
Comment 9 Felipe Heidrich CLA 2004-09-10 16:46:36 EDT
I was able to reproduce this bug on old builds but I can't reproduce it with 
build I20040907.

Doug, Travis, can you guys reproduce this problem on I20040907 ?
Comment 10 Felipe Heidrich CLA 2004-09-10 18:22:57 EDT
Okay, when I start eclipse I can not reproduce this problem, but after a couple
hours working on Eclipse I try again and then I could recreate it all the time.
Something has to happen before I can reproduce the bug, I just don't know what.
Comment 11 Douglas Pollock CLA 2004-09-13 09:07:20 EDT
This is easy for me to reproduce.  It has never failed to occur. 
Comment 12 Billy Biggs CLA 2005-03-07 18:00:50 EST
Here's a test case.  When the second Text is disposed on its key down, the focus
goes nowhere and the display filter does not work.  On Windows, when the second
Text is disposed, focus goes to the first Text.

public static void main(String[] args) {
	Display display = new Display();
	Shell shell = new Shell(display);
	display.addFilter(SWT.KeyDown, new Listener() {
		int count = 0;
		public void handleEvent(Event event) {
			System.out.println("Got a key down: " + count);
			count++;
		}
	});
	Text text = new Text(shell, SWT.BORDER);
	text.setBounds(20, 20, 200, 40);
	
	final Text text2 = new Text(shell, SWT.BORDER);
	text2.setBounds(80, 80, 200, 40);
	text2.addListener(SWT.KeyDown, new Listener() {
		public void handleEvent(Event event) {
			System.out.println("ok, here goes");
			text2.dispose();
		}
	});
	
	shell.open();
	while(!shell.isDisposed()) {
		if(!display.readAndDispatch()) display.sleep();
	}
	display.dispose();
}
Comment 13 Billy Biggs CLA 2005-05-01 22:25:53 EDT
Created attachment 20575 [details]
Proposed patch

Here's a proposal for a fix.  I think it's right, but it's dangerous to mess
with this sort of thing.
Comment 14 Travis Hume CLA 2005-05-03 13:12:07 EDT
Has that patch been included in a build yet?  I tried N20050503-0010 this
morning without success.
Comment 15 Billy Biggs CLA 2005-05-03 13:56:13 EDT
This patch is not safe and still needs work.  It is not included in any builds yet.
Comment 16 Billy Biggs CLA 2005-06-01 11:01:14 EDT
*** Bug 97555 has been marked as a duplicate of this bug. ***
Comment 17 Douglas Pollock CLA 2005-10-24 10:09:25 EDT
*** Bug 113278 has been marked as a duplicate of this bug. ***
Comment 18 Travis Hume CLA 2006-12-20 12:08:25 EST
Confirmed that is is still an issue with 3.3 M4.  Easy to reproduce:
1. Alt-Shift-Q Y (open sync view)
2. F5 (re-sync with server, refresh)
3. F12 (Should return to editor, but does nothing)

I, and my other keyboard only friends run into this constantly.
Note that we are now using subversive but have seen the problem with subclipse and the standard cvs plugin.
Comment 19 Michael Valenta CLA 2006-12-20 13:00:36 EST
*** Bug 164316 has been marked as a duplicate of this bug. ***
Comment 20 Felipe Heidrich CLA 2008-06-09 15:40:42 EDT
Still happens on 3.4 R4 (tested the snippet in 12).

Bog, haven't you fixed bugs in this area recently ?
Comment 21 Eric Williams CLA 2016-08-17 11:56:47 EDT
This is still reproducible. Assigning to Ian.
Comment 22 Eric Williams CLA 2016-08-17 11:57:07 EDT
*** Bug 123127 has been marked as a duplicate of this bug. ***
Comment 23 Ian Pun CLA 2016-09-06 15:26:05 EDT
I've added the proposed patch. I haven't discovered any possible use case that could case a dangerous side effect. Does anyone have a potential use case that would?
Comment 24 Eclipse Genie CLA 2016-09-06 16:52:17 EDT
New Gerrit change created: https://git.eclipse.org/r/80517
Comment 26 Eric Williams CLA 2016-09-08 12:45:11 EDT
(In reply to Eclipse Genie from comment #25)
> Gerrit change https://git.eclipse.org/r/80517 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=52881b02b736327002428947c3a54bd5fb1b6761

In master now, thanks for the patch Billy, and Ian for the investigation.
Comment 27 Eclipse Genie CLA 2016-09-09 02:44:34 EDT
New Gerrit change created: https://git.eclipse.org/r/80748
Comment 29 Alexander Kurtakov CLA 2016-09-09 02:52:27 EDT
This caused a lot of NPEs in latest nightly build:
java.lang.NullPointerException
at org.eclipse.swt.custom.CCombo.isFocusControl(CCombo.java:1091)
at org.eclipse.swt.custom.CCombo.setFocus(CCombo.java:1490)
at org.eclipse.swt.widgets.Control.fixFocus(Control.java:217)
at org.eclipse.swt.widgets.Control.releaseWidget(Control.java:4010)

Can be seen at http://download.eclipse.org/eclipse/downloads/drops4/N20160908-2000/testresults/html/org.eclipse.ui.tests_ep47N-unit-cen64_linux.gtk.x86_64_8.0.html .

I have reverted it - the way CCombo is implemented seems to cause race(?) condition. Before proceeding further on this bug please implement Test_org_eclipse_swt_custom_CCombo.test_isFocusControl and test_setFocus to not be empty methods - no matter how simple the tests are they should catch NPEs.
Comment 30 Arun Thondapu CLA 2016-09-09 07:57:49 EDT
Moving to M3 as there is more work to be done here...
Comment 31 Eclipse Genie CLA 2016-09-09 17:25:09 EDT
New Gerrit change created: https://git.eclipse.org/r/80853
Comment 32 Ian Pun CLA 2016-09-09 17:34:25 EDT
(In reply to Alexander Kurtakov from comment #29)
> This caused a lot of NPEs in latest nightly build:
> java.lang.NullPointerException
> at org.eclipse.swt.custom.CCombo.isFocusControl(CCombo.java:1091)
> at org.eclipse.swt.custom.CCombo.setFocus(CCombo.java:1490)
> at org.eclipse.swt.widgets.Control.fixFocus(Control.java:217)
> at org.eclipse.swt.widgets.Control.releaseWidget(Control.java:4010)
> 
> Can be seen at
> http://download.eclipse.org/eclipse/downloads/drops4/N20160908-2000/
> testresults/html/org.eclipse.ui.tests_ep47N-unit-cen64_linux.gtk.x86_64_8.0.
> html .
> 
> I have reverted it - the way CCombo is implemented seems to cause race(?)
> condition. Before proceeding further on this bug please implement
> Test_org_eclipse_swt_custom_CCombo.test_isFocusControl and test_setFocus to
> not be empty methods - no matter how simple the tests are they should catch
> NPEs.

Hey Alex,

I just committed a patch within Ccombo that will deal with the underlying issue; setFocusControl() was not overwritten correctly and did not take care of null exceptions. I have fixed that in Ccombo, but will definitely work on implementing the tests as well.
Comment 33 Ian Pun CLA 2016-09-12 09:54:16 EDT
*** Bug 185538 has been marked as a duplicate of this bug. ***
Comment 34 Eclipse Genie CLA 2016-09-13 11:31:43 EDT
New Gerrit change created: https://git.eclipse.org/r/81008
Comment 36 Eric Williams CLA 2016-09-16 16:13:28 EDT
(In reply to Eclipse Genie from comment #35)
> Gerrit change https://git.eclipse.org/r/81008 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=67e18320e2682697b68f564901b6459633fc9938

Merged updated fix, thanks for the patch Ian.