eclipse-pde / eclipse.pde

Eclipse Public License 2.0
25 stars 64 forks source link

Unable to open Advanced Search Dialog in Bundle Repository view more than once #1365

Closed ptziegler closed 1 month ago

ptziegler commented 1 month ago

To reproduce from a clean workspace:

Expectation:

The dialog should open again, just like it did the first time.

Actual Behavior:

The dialog fails to open with the following error, caused by the image set for the tab item already being disposed:

java.lang.IllegalArgumentException: Argument not valid
    at org.eclipse.swt.SWT.error(SWT.java:4903)
    at org.eclipse.swt.SWT.error(SWT.java:4837)
    at org.eclipse.swt.SWT.error(SWT.java:4808)
    at org.eclipse.swt.widgets.Widget.error(Widget.java:500)
    at org.eclipse.swt.widgets.Item.setImage(Item.java:180)
    at org.eclipse.swt.widgets.TabItem.setImage(TabItem.java:307)
    at org.eclipse.pde.bnd.ui.views.repository.AdvancedSearchDialog.createDialogArea(AdvancedSearchDialog.java:95)
    at org.eclipse.jface.dialogs.TitleAreaDialog.createContents(TitleAreaDialog.java:166)
    at org.eclipse.jface.window.Window.create(Window.java:431)
    at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1092)
    at org.eclipse.jface.window.Window.open(Window.java:788)
    at org.eclipse.pde.bnd.ui.views.repository.RepositoriesView$9.run(RepositoriesView.java:700)
    at org.eclipse.jface.action.Action.runWithEvent(Action.java:474)
    at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:581)
    at org.eclipse.jface.action.ActionContributionItem.lambda$5(ActionContributionItem.java:454)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:91)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4326)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1174)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4124)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3712)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1151)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1042)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
    at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:639)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:546)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:208)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:143)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:109)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:439)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:271)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:668)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:605)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1481)

Workaround

The Eclipse IDE needs to be restarted, every time the dialog is used.

Tested with:

Looking at the implementation of the dialog, I see that the images created by the search panel (line 92) are disposed together with the tab folder (line 104).

https://github.com/eclipse-pde/eclipse.pde/blob/22f953acc0f48bbc25ced055e528edc94fde613a/ui/org.eclipse.pde.bnd.ui/src/org/eclipse/pde/bnd/ui/views/repository/AdvancedSearchDialog.java#L92-L106

However, some implementations of the search panel like the ServiceSearchPanel don't create new images, but instead return shared images. Meaning: The AdvandedSearchDialog is wrongfully disposing shared images!

https://github.com/eclipse-pde/eclipse.pde/blob/22f953acc0f48bbc25ced055e528edc94fde613a/ui/org.eclipse.pde.bnd.ui/src/org/eclipse/pde/bnd/ui/views/repository/ServiceSearchPanel.java#L85-L87

HannesWell commented 1 month ago

Fixes via https://github.com/eclipse-pde/eclipse.pde/pull/1367.

Thank you @ptziegler for this report and he associated fix!