lukaszlenart opened a new pull request, #1914:
URL: https://github.com/apache/struts/pull/1914

   Fixes [WW-5724](https://issues.apache.org/jira/browse/WW-5724)
   
   `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.
   
   Two tests added to `StrutsLocalizedTextProviderTest`: 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.
   
   Why clone rather than the alternatives: building a fresh instance per call 
drops the parsing cache the WW-5540 work relies on, and synchronizing on the 
shared instance serializes all rendering. Measured over 1.2M renders on JDK 17, 
cloning was the cheapest of the three (176 ms, against 409 ms fresh-per-call 
and 556 ms synchronized).
   
   No configuration or API change. Applies to both maintenance lines; the 6.x 
backport follows.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to