- 
                Notifications
    You must be signed in to change notification settings 
- Fork 226
UI component being attempted to be disposed in a non-ui thread. #3232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2006, 2015 IBM Corporation and others. | ||
| * Copyright (c) 2006, 2025 IBM Corporation and others. | ||
| * | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
|  | @@ -18,8 +18,10 @@ | |
| import org.eclipse.jface.action.IMenuManager; | ||
| import org.eclipse.jface.viewers.IStructuredSelection; | ||
| import org.eclipse.swt.SWT; | ||
| import org.eclipse.swt.SWTException; | ||
| import org.eclipse.swt.dnd.Clipboard; | ||
| import org.eclipse.swt.events.KeyEvent; | ||
| import org.eclipse.swt.widgets.Display; | ||
| import org.eclipse.swt.widgets.Shell; | ||
| import org.eclipse.ui.IActionBars; | ||
| import org.eclipse.ui.ISharedImages; | ||
|  | @@ -55,9 +57,22 @@ public EditActionGroup(Shell aShell) { | |
|  | ||
| @Override | ||
| public void dispose() { | ||
| if (clipboard != null) { | ||
| clipboard.dispose(); | ||
| clipboard = null; | ||
| Display display = Display.getCurrent(); | ||
| if (display != null && !display.isDisposed()) { | ||
| if (clipboard != null && !clipboard.isDisposed()) { | ||
| clipboard.dispose(); | ||
| clipboard = null; | ||
| } | ||
| } else { | ||
| // Non-UI thread or display disposed | ||
| if (clipboard != null && !clipboard.isDisposed()) { | ||
| try { | ||
| clipboard.dispose(); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the clipboard really be disposed outside the UI thread?!? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally not supposed to be which might result into SWTException or resource leaks if disposal fails silently or false positives. Do you mean i can skip this line  | ||
| clipboard = null; | ||
| } catch (SWTException e) { | ||
| // Log a message if required. | ||
| } | ||
| } | ||
| } | ||
| super.dispose(); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not call super.dispose() anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @laeubi If that async runnable references anything indirectly tied to the context (logging, resources, actions), you can get into NPEs or disposed-object access. So this is Why super.dispose() was dropped. 
 So it was sacrificed for safety. But if we still want to be correct, the better solution is to still call super.dispose() inside the async block. That way we don’t silently skip the context cleanup from ActionGroup. We can do this way ::  | ||
| } | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not using
shell.getDisplay()it seems obvious here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah shell.getDisplay() is also a good choice. But i need to ensure that the Shell reference is not null and not disposed before calling shell.getDisplay(). Can i go ahead with this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking more can you use clipboard itself, it is already is disposed what is the point doing more work here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leubi
Sorry, was not able to get your intent. You meant to use Display.getCurrent() or shell.getDisplay()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we dont have this pr in place, while running CTabItemTest locally we'll again endup into original problem reshaped as( post pr 3241)
this problem shown in the console output below ->
Console_without_pr3232.txt
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deepika-u where do you get this is it windows?
I think it makes sense to go through each exception step by step, the first I see in your log is:
This looks like a bug in SWT (windows), because calling dispose on an already disposed component should be a no-op (and if device is disposed clipboard is gone anyways...).
Looking into other widgets implementations the do
if (display.thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);so calling
getThreadinstead of access the field directly seems the culprit here.