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

Bug 333533

Summary: Invalid thread access on 'add depenencies' in Manifest editor
Product: [Eclipse Project] PDE Reporter: Gunnar Wagenknecht <gunnar>
Component: UIAssignee: Curtis Windatt <curtis.windatt.public>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: ankur_sharma, curtis.windatt.public
Version: 3.7   
Target Milestone: 3.8 M2   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Proposed fix
none
Fix for the regression none

Description Gunnar Wagenknecht CLA 2011-01-05 03:25:51 EST
3.7 M4

Add a bunch of bundles to  "Automated Management of Dependencies" section and make sure that some Java code in the bundle references some new packages.

Select "Import-Package" radio button and click "add dependencies" link.

From the stacktrace below it looks like the operation is run in a background job. However, the model changes must be processed in the UI thread.




org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:4091)
at org.eclipse.swt.SWT.error(SWT.java:4006)
at org.eclipse.swt.SWT.error(SWT.java:3977)
at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:359)
at org.eclipse.swt.widgets.Table.getItemCount(Table.java:2606)
at org.eclipse.jface.viewers.TableViewer.doGetItemCount(TableViewer.java:210)
at org.eclipse.jface.viewers.AbstractTableViewer.indexForElement(AbstractTableViewer.java:554)
at org.eclipse.jface.viewers.AbstractTableViewer.add(AbstractTableViewer.java:262)
at org.eclipse.jface.viewers.AbstractTableViewer.add(AbstractTableViewer.java:315)
at org.eclipse.pde.internal.ui.editor.plugin.ImportPackageSection.modelChanged(ImportPackageSection.java:567)
at org.eclipse.pde.internal.core.text.AbstractEditingModel.fireModelChanged(AbstractEditingModel.java:221)
at org.eclipse.pde.internal.core.bundle.BundleObject.fireModelChanged(BundleObject.java:60)
at org.eclipse.pde.internal.core.bundle.BundleObject.fireStructureChanged(BundleObject.java:55)
at org.eclipse.pde.internal.core.text.bundle.CompositeManifestHeader.addManifestElement(CompositeManifestHeader.java:123)
at org.eclipse.pde.internal.core.text.bundle.CompositeManifestHeader.addManifestElement(CompositeManifestHeader.java:99)
at org.eclipse.pde.internal.core.text.bundle.BasePackageHeader.addPackage(BasePackageHeader.java:34)
at org.eclipse.pde.internal.ui.search.dependencies.AddNewDependenciesOperation.addImportPackages(AddNewDependenciesOperation.java:410)
at org.eclipse.pde.internal.ui.search.dependencies.AddNewDependenciesOperation.addDependencies(AddNewDependenciesOperation.java:363)
at org.eclipse.pde.internal.ui.search.dependencies.AddNewDependenciesOperation.handleNewDependencies(AddNewDependenciesOperation.java:341)
at org.eclipse.pde.internal.ui.search.dependencies.AddNewDependenciesOperation.execute(AddNewDependenciesOperation.java:89)
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2313)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
at org.eclipse.pde.internal.ui.search.dependencies.AddNewDependenciesAction$2.runInWorkspace(AddNewDependenciesAction.java:58)
at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:38)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Comment 1 Curtis Windatt CLA 2011-01-05 11:45:06 EST
The UI editor should handle the UI changes in the correct thread.  It shouldn't assume that all model change events will be fired in the UI thread.
Comment 2 Curtis Windatt CLA 2011-07-14 12:13:58 EDT
Created attachment 199680 [details]
Proposed fix

Gunnar, can you please give the patch a try.  The fix runs the editor updating in a UI thread. I changed both the import package and require bundle sections.
Comment 3 Curtis Windatt CLA 2011-07-28 15:27:49 EDT
Patch applied to HEAD.  Please verify Gunnar.
Comment 4 Ankur Sharma CLA 2011-08-03 08:44:06 EDT
There is a regression. I am seeing duplicate entries in the Imported Packages sections.

How to repro in I20110802-2000:
1. Create an empty plug-in. Let is contribute to UI (that is, o.e.ui and o.e.core.runtime be already there in the required plug-in section)
2. Add o.e.pde.ui, pde.core and pde.launching to the 'automated mgmt of dependencies'
2. Create a class and add references to some pde APIs. I used this

public class C {

	IBaseModel model;
	IBasePluginWizard wiz;
	PDESourcePathProvider p;
}

3. In 'automated..' section select the import-package radio and click 'add dependencies'

Result: The imported packages and 2 entries for each of the three packages.

Try to delete them, you can delete only one instance of each.
Comment 5 Curtis Windatt CLA 2011-08-11 15:42:35 EDT
Created attachment 201348 [details]
Fix for the regression

The regression is caused by the model having no way to coalesce model changes.  In addition, the model updates are poorly designed as the first creation of the header comes as a CHANGE event for the bundle, while future updates come as INSERT events for just the import header.  The required bundle section doesn't experience the same problem because it doesn't have this odd model setup.  I looked at changing the model structure, but after sinking several hours into it I haven't found a workable solution.

This patch fixes it by making sure we don't add a duplicate package object to the UI.

I found a problem with the remove functionality.  This is fixed by updating the buttons after performing the remove.
Comment 6 Curtis Windatt CLA 2011-08-11 15:43:41 EDT
Applied the additional fix to HEAD.
Comment 7 Curtis Windatt CLA 2011-08-11 15:46:07 EDT
It appears the attached patch missed one of the changes.  In RequiresSection.java (from the plugin editor, not the feature editor), the same updateButtons() call is made at the end of the remove inside the UIJob.
Comment 8 Ankur Sharma CLA 2011-09-14 05:49:52 EDT
Verified in I20110913-0200