Add caching regression tests for FontRegistry - #4249
Open
HeikoKlare wants to merge 1 commit into
Open
Conversation
Contributor
HeikoKlare
marked this pull request as ready for review
August 13, 2026 17:47
Guard the font-caching invariants that FontRegistry relies on: get(), getBold() and getItalic() return the identical Font instance across repeated lookups, a symbolic name that was never registered stably falls back to the default font, and the default font stays stable when other names are looked up (including from a non-UI thread). Also cover the surrounding put() contract: hasValueFor()/getKeySet() only reflect explicitly registered names, getFontData()/getDescriptor() fall back to the default like get() does, put() only fires a property change when the data actually changes, put() with new data invalidates previously cached base/bold/italic fonts, and a font replaced by put() stays usable until its Display is disposed rather than being disposed immediately.
HeikoKlare
force-pushed
the
fontregistry-tests
branch
from
August 13, 2026 17:47
a1787e2 to
93b0e24
Compare
There was a problem hiding this comment.
Pull request overview
Adds regression tests to FontRegistry (JFace resources) to guard key caching and fallback invariants, especially around repeated lookups, default-font stability, and update/replace semantics (including multi-Display behavior on Windows).
Changes:
- Add tests asserting stable/identical
Fontinstances across repeatedget()/getBold()/getItalic()calls. - Add tests for fallback behavior of unknown symbolic names and for
hasValueFor()/getKeySet()only reflecting explicitly registered entries. - Add tests for
put()semantics (property-change emission only on actual data changes, cache invalidation on updates, and delayed disposal untilDisplaydisposal).
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+208
to
+223
| FontRegistry fontRegistry = new FontRegistry(); | ||
| Display secondDisplay = initializeDisplayInSeparateThread(); | ||
|
|
||
| Font original = secondDisplay.syncCall(() -> { | ||
| fontRegistry.put("myfont", new FontData[] { new FontData("Arial", 12, SWT.NORMAL) }); | ||
| return fontRegistry.get("myfont"); | ||
| }); | ||
|
|
||
| secondDisplay | ||
| .syncExec(() -> fontRegistry.put("myfont", new FontData[] { new FontData("Arial", 18, SWT.BOLD) })); | ||
| // the font may still be in use elsewhere, so it must not be disposed right away | ||
| assertFalse(original.isDisposed(), "previous font must stay usable until its display is disposed"); | ||
|
|
||
| secondDisplay.syncExec(secondDisplay::dispose); | ||
| assertTrue(original.isDisposed(), "stale font must be disposed once its display is disposed"); | ||
| } |
Comment on lines
+173
to
+174
| assertEquals(fontRegistry.get(JFaceResources.DEFAULT_FONT), first); | ||
| assertEquals(first, second); |
| } | ||
|
|
||
| @Test | ||
| public void put_withNewDataInvalidatesPreviouslyCachedFont() { |
Comment on lines
+147
to
+153
| AtomicReference<Font> fontFromNonUIThread = new AtomicReference<>(); | ||
| Font defaultFont = fontRegistry.get(JFaceResources.DEFAULT_FONT); | ||
| Thread nonUiThread = new Thread(() -> fontFromNonUIThread.set(fontRegistry.get("myfont"))); | ||
| nonUiThread.start(); | ||
| nonUiThread.join(); | ||
| assertEquals(defaultFont, fontRegistry.get(JFaceResources.DEFAULT_FONT)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Guard the font-caching invariants that FontRegistry relies on: get(), getBold() and getItalic() return the identical Font instance across repeated lookups, a symbolic name that was never registered stably falls back to the default font, and the default font stays stable when other names are looked up (including from a non-UI thread).
Also cover the surrounding put() contract: hasValueFor()/getKeySet() only reflect explicitly registered names, getFontData()/getDescriptor() fall back to the default like get() does, put() only fires a property change when the data actually changes, put() with new data invalidates previously cached base/bold/italic fonts, and a font replaced by put() stays usable until its Display is disposed rather than being disposed immediately.
Note
We are currently invesigating issues with
FontRegistryin multi-display usage scenarios on Windows. In order to prevent regression (during according fixes and other changes toFontRegistry), this adds a bunch of tests for essential contracts of the class as theFontRegistryis badly tested right now.