Bug 549059 - RAT triggered after disposing the context under certain conditions
Summary: RAT triggered after disposing the context under certain conditions
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.6   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-08 07:31 EDT by Alexander Zakusylo CLA
Modified: 2021-10-04 16:48 EDT (History)
5 users (show)

See Also:


Attachments
stacktrace (2.42 KB, text/plain)
2021-01-07 07:26 EST, Wim Jongman CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Zakusylo CLA 2019-07-08 07:31:10 EDT
RATs may continue to get triggered after disposing the context

We faced this issue in our RCP application when user drags an editor to another window and then closes the first window.

The root cause is that listeners added by EclipseContext#trackAccess may stay forever in child contexts.

I was able to find out a minimal reproducible snippet:

                IEclipseContext root = EclipseContextFactory.create("root");
		IEclipseContext oldParent = root.createChild("oldParent");
		IEclipseContext newParent = root.createChild("newParent");
		IEclipseContext leaf = oldParent.createChild("leaf");

		oldParent.runAndTrack(new RunAndTrack() {
			@Override
			public boolean changed(IEclipseContext context) {
				IEclipseContext activeLeaf = context.getActiveLeaf();
				System.err.println("oldParent's active leaf = " + activeLeaf);
				return true;
			}
		});

		leaf.activateBranch();
		leaf.setParent(newParent);


		oldParent.dispose();
		System.err.println("oldParent is disposed now !!");

		leaf.activateBranch(); // <---- THIS CALL TRIGGERS RAT IN DISPOSED oldParent


Wrapping the RAT code into RunAndTrack.runExternalCode fixes this snippet, but in our app RAT WorkbenchWindow.setup() is being triggered (WorkbenchWindow.java:724)

		RunAndTrack menuChangeManager = new RunAndTrack() {
		@Override
		public boolean changed(IEclipseContext context) {
			ExpressionInfo info = new ExpressionInfo();
			IEclipseContext leafContext = windowContext.getActiveLeaf();
                . . .
Comment 1 Andrey Loskutov CLA 2019-07-08 11:14:39 EDT
Is this a regression in 4.12?
Comment 2 Alexander Zakusylo CLA 2019-07-09 05:14:35 EDT
Reproducible also on 4.6, so not a 4.12 regression
Comment 3 Andrey Loskutov CLA 2019-07-09 05:17:13 EDT
(In reply to Oleksandr Zakusylo from comment #2)
> Reproducible also on 4.6, so not a 4.12 regression

Thanks. If you want this fixed, providing a patch is the best way.
https://wiki.eclipse.org/Platform/How_to_Contribute
Comment 4 Eclipse Genie CLA 2019-08-02 11:11:46 EDT
New Gerrit change created: https://git.eclipse.org/r/146981
Comment 5 Lars Vogel CLA 2020-05-12 04:45:51 EDT
Oleksandr, could you describe how I can reproduce the issue?
Comment 6 Alexander Zakusylo CLA 2020-05-12 08:04:16 EDT
Lars, run the piece of code from the bug description.
Expected result: "oldParent is disposed now !!" should be the last visible line in console.
Actual result: "oldParent's active leaf = ...." appears in console AFTER "oldParent is disposed now !!"
Comment 7 Lars Vogel CLA 2020-05-19 04:45:34 EDT
(In reply to Alexander Zakusylo from comment #6)
> Lars, run the piece of code from the bug description.
> Expected result: "oldParent is disposed now !!" should be the last visible
> line in console.
> Actual result: "oldParent's active leaf = ...." appears in console AFTER
> "oldParent is disposed now !!"

I don't dare to touch that code so close to the end of the release cycle. 

I will try to review very early 4.17. Please ping me early 4.17, in case I do not act proactively.

If someone else is more daring, please review and move it back to 4.16.
Comment 8 Lars Vogel CLA 2020-11-18 08:32:11 EST
Mass change to 4.19 M1, please update the target if you have other plans.
Comment 9 Alexander Kurtakov CLA 2021-01-07 03:07:22 EST
Mass move 4.19 M1 bugs to M3
Comment 10 Wim Jongman CLA 2021-01-07 07:26:52 EST
Created attachment 285219 [details]
stacktrace

I also have issues with this.

Specifically, when a new window is created and the other is closed, there are issues. I can work with you on this.

Is this stacktrace also what you are seeing?
Comment 11 Kalyan Prasad Tatavarthi CLA 2021-06-04 00:55:20 EDT
Mass Move out of 4.20
Comment 12 Eclipse Genie CLA 2021-10-04 16:48:58 EDT
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.runtime/+/186122