Skip to content

Conversation

@deepika-u
Copy link
Contributor

getActiveWindow()
getSplashShell(Display display)

  • Added guards to safely handle cases where the Display is null or disposed.
  • Prevents SWTException: Widget is disposed when querying the active shell during shutdown avoiding crashes.

These changes make both methods more robust during application startup and shutdown, eliminating crashes caused by accessing disposed SWT resources.

Raised this pr as discussed in -> #3232 (comment)

@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2025

Test Results

 2 799 files  ±0   2 799 suites  ±0   1h 59m 49s ⏱️ + 17m 18s
 7 954 tests ±0   7 727 ✅ +1  227 💤 ±0  0 ❌  - 1 
23 396 runs  ±0  22 668 ✅ +1  728 💤 ±0  0 ❌  - 1 

Results for commit 3668598. ± Comparison against base commit dc1eea9.

♻️ This comment has been updated with latest results.

return null;
}

if (display.isDisposed()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not already be checked in line 1178?

Copy link
Contributor Author

@deepika-u deepika-u Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this being a timing issue, have added the check before its being used again.

In shutdown scenarios, it is possible that the Display was disposed in between (e.g., another thread closed the workbench).

Without the second check, Shell.internal_new() would throw an SWTException: Widget is disposed.

So this second check is a race-condition guard. It’s defensive programming against the Display being disposed after the first check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But who should dispose the display in the meanwhile? This looks a bit fishy here so is this really called outside the event thread?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right - under normal circumstances, the Display is only disposed on the UI thread at shutdown. If we can guarantee that getSplashShell() is always called from the UI thread, then the second check is redundant.

However, since this is a static utility used during startup/shutdown, I was not 100% sure whether it’s always invoked on the UI thread. If there is no non UI thread caller, I can drop the second check. Otherwise, it serves as a defensive guard against race conditions.

}
Shell splashShell = (Shell) display.getData(DATA_SPLASH_SHELL);
if (splashShell != null)
if (splashShell != null && !splashShell.isDisposed())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the shell is disposed already, should we probably return null here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean this way?

Shell splashShell = (Shell) display.getData(DATA_SPLASH_SHELL);
if (splashShell != null) {
    if (!splashShell.isDisposed()) {
        return splashShell;
    } else {
        return null; 
    }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but it depends on the error case I think we like to handle. So in what cases the shell is disposed? Is it only during shutdown? Then it should be save to early exit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with early exit. So updated as per that.

@deepika-u deepika-u force-pushed the safe_gaurds_for_widget_disposal branch from ac6595f to 3668598 Compare September 4, 2025 15:10
@laeubi laeubi merged commit 23d4b86 into eclipse-platform:master Sep 5, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants