jbushmaster007 / anyedittools

Automatically exported from code.google.com/p/anyedittools
Other
1 stars 0 forks source link

Potential invalid thread access errors in the truck version #62

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi-

There may be a potential invalid thread access errors in the following class:

de.loskutov.anyedit.actions.ConvertAllInFolderAction

In method:

public void run(final IAction action) {
    IPreferenceStore preferenceStore = AnyEditToolsPlugin.getDefault().getPreferenceStore();

    boolean shouldAsk = preferenceStore.getBoolean(IAnyEditConstants.ASK_BEFORE_CONVERT_ALL_IN_FOLDER);

    if (shouldAsk) {
            MessageDialogWithToggle dialogWithToggle = MessageDialogWithToggle.openYesNoQuestion(AnyEditToolsPlugin.getShell(),

//code omitted below

===================
Since an Action will not always be invoked in a UI-thread, thus, it seems that 
the run method will call "MessageDialogWithToggle.openYesNoQuestion" method, 
which will eventually access SWT GUI object, lead the "checkWidget" method 
fail.  

I also note in some code part, the authors have already note this case, for 
example, in de.loskutov.anyedit.actions.ConvertAllAction#run, the authors 
explicitly wrapped the GUI object access code as:

PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
                public void run() {
                    AnyEditToolsPlugin.errorDialog("'Tabs<->spaces' operation failed", e);
                }
            });

to avoid directly access the GUI object via a non-UI thread.

If I mis-understood some logic in the program, please let me know.

thanks

-Sai

Original issue reported on code.google.com by racezh...@gmail.com on 18 Jan 2012 at 11:13

GoogleCodeExporter commented 8 years ago
This is not a bug. The run is always executed from UI thread, so not check is 
needed in the ConvertAllInFolderAction. ConvertAllAction run code immediately 
starts a job, so the code there is NOT running in UI thread, therefore the 
check there is needed.

Closing as invalid.

CU
Andrey

Original comment by iloveeclipse on 19 Jan 2012 at 2:56