WW-5724 Hand out a clone of the cached MessageFormat (6.x) - #1915
Open
lukaszlenart wants to merge 1 commit into
Open
WW-5724 Hand out a clone of the cached MessageFormat (6.x)#1915lukaszlenart wants to merge 1 commit into
lukaszlenart wants to merge 1 commit into
Conversation
AbstractLocalizedTextProvider caches MessageFormat instances by pattern and locale and returned the cached instance itself from buildMessageFormat. MessageFormat is not thread-safe, so concurrent callers rendering the same message formatted through one shared instance; with a date or time sub-format that produced output for the wrong argument or an exception. buildMessageFormat now returns a clone of the cached instance, so the cached entry is only ever a template and is never formatted directly. MessageFormat.clone() deep-copies the sub-formats. The pattern-parsing cache is kept; measured against a fresh instance per call and against synchronizing on the shared instance, cloning is the cheapest of the three. Backport of the main change (#1914) to the 6.x line. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
lukaszlenart
marked this pull request as ready for review
September 11, 2026 13:49
|
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.



Fixes WW-5724
Backport of #1914 to the 6.x line.
AbstractLocalizedTextProvidercachesMessageFormatinstances by pattern and locale and returned the cached instance itself frombuildMessageFormat.MessageFormatis not thread-safe, so concurrent callers rendering the same message formatted through one shared instance; with a date or time sub-format that produced output for the wrong argument or an exception.buildMessageFormatnow returns a clone of the cached instance, so the cached entry is only ever a template and is never formatted directly.MessageFormat.clone()deep-copies the sub-formats on Java 8 as well (Calendar,DigitList,DateFormatSymbols). The pattern-parsing cache is kept.Two tests added to
StrutsLocalizedTextProviderTest, matching the main change: one asserts two lookups of the same pattern no longer return the same instance while the cache still holds one entry; the other renders a{0,date,short}message from four threads with distinct dates and asserts every output matches its own argument. Both failed before the change.No configuration or API change.
🤖 Generated with Claude Code