Skip to content

Force using the ROOT locale when formatting to avoid involving the default locale when numbers are converted to strings - #16025

Merged
lorban merged 5 commits into
jetty-12.1.xfrom
fix/12.1.x/16020-locale-independent-header-formatting
Oct 26, 2026
Merged

lorban merged 5 commits into
jetty-12.1.xfrom
fix/12.1.x/16020-locale-independent-header-formatting

Conversation

@lorban

@lorban lorban commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

All the places where String.format("...%d...", ...) was used were modified to explicitly use Locale.ROOT to avoid involving the default locale.

Fixes #16020

…locale when numbers are converted to strings

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
…locale when numbers are converted to strings

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
@lorban lorban moved this to 👀 In review in Jetty 12.1.15 - FROZEN Oct 23, 2026

@joakime joakime left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We've used String.format(Locale.ROOT, "%.2f %d %,f", floatNum, intNum, doubleNum) in the past, why did this PR choose to go the concat route instead?

Example:

return String.format(Locale.ROOT, "%s@%x[%s,q=%f,i=%d]",
getClass().getSimpleName(),
hashCode(),
getValue(),
getWeight(),
_index);

@joakime

joakime commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

This PR seems to want to correct our String.format() behaviors with numbers, which is good.
But it seems to have been solely focused on "%d", and not "%f".

@lorban

lorban commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

@joakime what %f? did I miss something?

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
@lorban
lorban requested a review from joakime October 23, 2026 14:37
@joakime

joakime commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

@joakime what %f? did I miss something?

It felt like we were missing the %f usages (formatting for floats/doubles) as well, but it looks like we handle them correctly (or at least I cannot find any other examples of bad usages)

Examples:

QuotedQualityCSV

return String.format(Locale.ROOT, "%s@%x[%s,q=%f,i=%d]",
getClass().getSimpleName(),
hashCode(),
getValue(),
getWeight(),
_index);

SampleStatistic

return String.format(Locale.ROOT, "%s@%x{count=%d,max=%d,mean=%f,total=%d,variance=%f,stddev=%f}", getClass().getSimpleName(), hashCode(), getCount(), getMax(), getMean(), getTotal(), getVariance(), getStdDev());

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
@joakime

joakime commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Guess the title of this PR is no longer accurate.

@lorban lorban changed the title Replace formatting with concatenations to avoid involving the locale when numbers are converted to strings Force using the ROOT locale when formatting to avoid involving the default locale when numbers are converted to strings Oct 24, 2026

@sbordet sbordet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing:

  • ByteRange.toHeaderValue()
  • ContentDecoder.Factories.put() -> Same problem but with DecimalFormat
  • ShutdownService.listen()

Tests use Locale ar-EG, but Locale ar switched digits from arabic to roman in Java 25.
If ar-EG changes the same way, these tests would pass without testing anything.
Force native digits using the -u-nu- extension, for example hi-IN-u-nu-deva or ar-EG-u-nu-arab.

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
@lorban
lorban requested a review from sbordet October 26, 2026 10:43
@sbordet
sbordet self-requested a review October 26, 2026 11:22
@lorban
lorban merged commit 116ff29 into jetty-12.1.x Oct 26, 2026
11 checks passed
@github-project-automation github-project-automation Bot moved this from 👀 In review to ✅ Done in Jetty 12.1.15 - FROZEN Oct 26, 2026
@lorban
lorban deleted the fix/12.1.x/16020-locale-independent-header-formatting branch October 26, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug For general bugs on Jetty side

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

Origin.Address.asString(), Strict-Transport-Security and Alt-Svc are formatted with the default Locale (non-ASCII digits)

3 participants