Skip to content

Avoid eagerly creating the default font as a side effect of put() - #4265

Open
HeikoKlare wants to merge 1 commit into
eclipse-platform:masterfrom
HeikoKlare:fontregistry-multidisplay-step1b
Open

Avoid eagerly creating the default font as a side effect of put()#4265
HeikoKlare wants to merge 1 commit into
eclipse-platform:masterfrom
HeikoKlare:fontregistry-multidisplay-step1b

Conversation

@HeikoKlare

Copy link
Copy Markdown
Contributor

When put() replaces an already-realized font, it obtains the current default font via defaultFontRecord() purely to compare it against the replaced font's instances for staleness. But defaultFontRecord() does not just look up an already-realized default font — it also creates and caches one if none exists yet.

So replacing an unrelated symbolic name's font allocates a native default-font handle earlier than needed, merely as a side effect of an identity comparison. And because createFont() registers the data it used, this is directly observable: hasValueFor(JFaceResources.DEFAULT_FONT) flips to true and getKeySet() starts reporting the default font, purely because some other name was re-put.

Look up the already-cached default font record directly instead, tolerating that it may not exist yet — in which case the replaced font's instances are unconditionally treated as stale, exactly as before, since they can never equal a still-unrealized default font.

Includes a regression test asserting that replacing a realized font leaves the default font unregistered.

🤖 Generated with Claude Code

When put() replaced an already-realized font, it obtained the current
default font via defaultFontRecord() purely to compare it against the
replaced font's instances for staleness. defaultFontRecord() does not
just look up an already-realized default font, it also creates and
caches one if none exists yet. As a result, replacing an unrelated
symbolic name's font could silently allocate and cache a native
default-font handle earlier than it would otherwise have been needed,
merely as a side effect of an identity comparison.

Creating that font is not the only consequence. createFont() registers
the data it used under the symbolic name it created the font for, so
replacing an unrelated font also registered font data for the default
font that no client ever asked for. That is directly observable:
hasValueFor(JFaceResources.DEFAULT_FONT) flipped to true, and
getKeySet() started reporting the default font, purely because some
other name had been re-put.

Look up the already-cached default font record directly instead,
tolerating that it may not exist yet (in which case the replaced
font's instances are unconditionally treated as stale, same as
before, since they can never equal a still-unrealized default font).

Add a regression test asserting that replacing a realized font leaves
the default font unregistered. Beyond the observable effect above, this
also matters once the font cache stops being a single shared cache, so
that comparing against a display's default font does not have the side
effect of allocating that default font on an unrelated display.

Assisted-by: Claude Opus 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates FontRegistry.put() to avoid eagerly realizing/creating the default font as an observable side effect when replacing an already-realized non-default font. This prevents hasValueFor(JFaceResources.DEFAULT_FONT) and getKeySet() from changing solely due to identity comparisons during stale-font retirement.

Changes:

  • Update FontRegistry.put(...) to look up an already-cached default FontRecord directly (and tolerate it being absent) instead of calling defaultFontRecord().
  • Add a regression test ensuring replacing a realized font does not register the default font name/data.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FontRegistry.java Avoids default font realization/registration side effects during stale-font handling when replacing an existing realized font.
tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/resources/FontRegistryTest.java Adds coverage asserting put() replacement does not implicitly register the default font.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@HeikoKlare
HeikoKlare marked this pull request as ready for review August 21, 2026 15:07
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

   858 files  ±0     858 suites  ±0   47m 33s ⏱️ - 3m 0s
 8 173 tests +1   7 930 ✅ +2  243 💤 ±0  0 ❌ ±0 
20 421 runs  +3  19 765 ✅ +4  656 💤 ±0  0 ❌ ±0 

Results for commit e618f30. ± Comparison against base commit 5b3e6dd.

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