Bug 570059 - ClassCastException in SelectionServiceListener
Summary: ClassCastException in SelectionServiceListener
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.14   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Jens Lideström CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2021-01-04 13:40 EST by Hans-Erik Floryd CLA
Modified: 2021-01-09 14:24 EST (History)
2 users (show)

See Also:


Attachments
Sample plugin project (15.08 KB, application/zip)
2021-01-04 13:40 EST, Hans-Erik Floryd CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hans-Erik Floryd CLA 2021-01-04 13:40:35 EST
Created attachment 285170 [details]
Sample plugin project

The following code works for versions < 4.14:

		IObservableValue<Object> observe = WorkbenchProperties.singleSelection().observe(getSite().getService(ISelectionService.class));

		ISideEffect.create(new Runnable() {			
			@Override
			public void run() {			
				Object value = observe.getValue();
				System.out.println(value);
			}
		});

With version 4.14 and newer a ClassCastException is thrown when fireChanged is called in SelectionServiceListener.java as a result of clicking on e.g. the Project Explorer view:

java.lang.ClassCastException: class org.eclipse.ui.navigator.resources.ProjectExplorer cannot be cast to class org.eclipse.ui.ISelectionService(org.eclipse.ui.navigator.resources.ProjectExplorer is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @1a25ef08; org.eclipse.ui.ISelectionService is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @79316697)
	at org.eclipse.ui.internal.databinding.SelectionServiceListener.selectionChanged(SelectionServiceListener.java:64)
	at org.eclipse.ui.internal.e4.compatibility.SelectionService.notifyListeners(SelectionService.java:240)
	at org.eclipse.ui.internal.e4.compatibility.SelectionService.handleSelectionChanged(SelectionService.java:94)
	at org.eclipse.ui.internal.e4.compatibility.SelectionService.lambda$0(SelectionService.java:68)
	at org.eclipse.e4.ui.internal.workbench.SelectionAggregator$1.run(SelectionAggregator.java:123)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
[...]

This change in behaviour was introduced by commit d3c22327f2bdf89bebd15219c8f0f1d6671eb036.
Comment 1 Eclipse Genie CLA 2021-01-05 15:16:58 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/174299
Comment 2 Jens Lideström CLA 2021-01-05 15:17:35 EST
Hello HE, and thanks for reporting with a such clear demonstration of the bug.

The problem is because SelectionListener uses a non-standard value as the source
argument to fireChange. This was not taken into consideration when adding type parameters, leading to ClassCastExceptions.

A fix has been pushed.
Comment 3 Hans-Erik Floryd CLA 2021-01-07 05:25:07 EST
Hi Jens! Thanks for the quick fix. I see the build is failing although it seems unrelated to this patch?
Comment 4 Jens Lideström CLA 2021-01-07 05:38:32 EST
(In reply to Hans-Erik Floryd from comment #3)
> I see the build is failing although it seems unrelated to this patch?

It seems like they have introduced a feature that fails builds during the master branch freeze time.

There is a master branch freeze time during a short period before each major release.