Skip to content

Fix theme-race in decorator manager and modernize decorator package#16

Open
vogella wants to merge 2 commits intomasterfrom
fix/decorator-theme-race
Open

Fix theme-race in decorator manager and modernize decorator package#16
vogella wants to merge 2 commits intomasterfrom
fix/decorator-theme-race

Conversation

@vogella
Copy link
Copy Markdown
Owner

@vogella vogella commented Apr 22, 2026

Tree rows with a decorator-provided background or foreground can render with stale colors when the workbench starts with a theme that differs from the default, because DecorationResult caches Color and Font references at decoration time and the registry is still being populated when early decoration jobs fire. The same issue shows up on a runtime theme switch.

This branch first applies a behaviour-preserving cleanup of the decorator package (raw-type generics, enhanced-for, String.split, RunnableData as a record), then adds an IPropertyChangeListener on the workbench IThemeManager in DecoratorManager that clears the decoration cache and fires a general LabelProviderChangedEvent when theme colors or fonts change, so viewers pick up fresh values.

Target for the upstream work is eclipse-platform#3926. This PR is against the vogella fork so the branch can be built into an IDE and tested before proposing anything upstream.

@iloveeclipse
Copy link
Copy Markdown

Please rebase on master, PR contains lot of unrelated changes.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modernizes several Eclipse UI components by migrating legacy logging and status utilities to the ILog and Status APIs, generifying collections, and adopting modern Java features like records. Notable functional improvements include adding sortable columns to the Smart Import wizard, a cancel icon in the Quick Access search field, and extracting Quick Access matching logic into a dedicated utility class for better testability. Additionally, several test suites were updated to JUnit 5. Feedback was provided regarding a potential StringIndexOutOfBoundsException in DecoratorManager.java caused by the switch from StringTokenizer to String.split when processing preference strings.

Comment on lines 743 to 751
for (String nextValuePair : preferenceValue.split(PREFERENCE_SEPARATOR)) {
// Strip out the true or false to get the id
String id = nextValuePair.substring(0, nextValuePair.indexOf(VALUE_SEPARATOR));
if (nextValuePair.endsWith(P_TRUE)) {
enabledIds.add(id);
} else {
disabledIds.add(id);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The transition from StringTokenizer to String.split introduces a potential regression in robustness. String.split can return empty strings if the preference value contains leading or consecutive separators (e.g., ",id:true"), whereas StringTokenizer would skip them. If an empty string is processed, nextValuePair.indexOf(VALUE_SEPARATOR) will return -1, causing substring(0, -1) to throw a StringIndexOutOfBoundsException. It is safer to check if the separator exists before attempting to extract the ID.

			for (String nextValuePair : preferenceValue.split(PREFERENCE_SEPARATOR)) {
				int separatorIndex = nextValuePair.indexOf(VALUE_SEPARATOR);
				if (separatorIndex != -1) {
					String id = nextValuePair.substring(0, separatorIndex);
					if (nextValuePair.endsWith(P_TRUE)) {
						enabledIds.add(id);
					} else {
						disabledIds.add(id);
					}
				}
			}

@vogella
Copy link
Copy Markdown
Owner Author

vogella commented Apr 22, 2026

Please rebase on master, PR contains lot of unrelated changes.

You may not have noticed that this is just living in my clone. So please ignore this until I'm really to share it with eclipse.platform.ui The link is unfortunately automatically created by Github.

@vogella vogella closed this Apr 22, 2026
@vogella vogella reopened this Apr 22, 2026
vogella added 2 commits April 22, 2026 22:03
Behavior-preserving cleanup of the org.eclipse.ui.internal.decorators
package:

- DecorationResult: generify raw List fields to List<String>, replace
  ListIterator loops with enhanced-for.
- DecoratorManager: replace explicit Iterator loop with enhanced-for,
  replace StringTokenizer with String.split, drop toArray with a
  pre-sized array in favour of toArray(new T[0]), remove the now
  unused imports.
- LightweightDecoratorManager: convert the RunnableData holder to a
  record, drop toArray with a pre-sized array.

In preparation for eclipse-platform#3926
DecorationResult holds Color and Font references obtained from the
active theme's registries at the time a decoration is computed. When
the workbench starts with a theme that differs from the default, the
color registry is populated after some decoration jobs have already
cached references, leaving rows that carry a decorator-provided
background or foreground painted with stale values from the default
theme. The same stale-reference issue shows up on a runtime theme
switch.

Install an IPropertyChangeListener on the workbench IThemeManager,
which forwards property changes from the current theme's color and
font registries and fires CHANGE_CURRENT_THEME on theme switches. When
any of those events fire, clear the DecorationScheduler result cache
and fire a general LabelProviderChangedEvent so viewers re-query
decorations and pick up fresh colors and fonts.

Fixes eclipse-platform#3926
@vogella vogella force-pushed the fix/decorator-theme-race branch from 86e7d63 to 150eea8 Compare April 22, 2026 20:03
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