Skip to content

Tomcat's new 'maxLocaleCount' property cannot be easily configured - #52367

Merged
wilkinsona merged 1 commit into
spring-projects:4.0.xfrom
be-hase:tomcat-max-locale-count
Oct 27, 2026
Merged

wilkinsona merged 1 commit into
spring-projects:4.0.xfrom
be-hase:tomcat-max-locale-count

Conversation

@be-hase

@be-hase be-hase commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

This PR adds a server.tomcat.max-locale-count property to configure Tomcat's new
maxLocaleCount connector attribute.

Background

Tomcat 11.0.27 introduced this attribute with a default of 10
(apache/tomcat@c45c9b4), and Spring Boot
4.0.9 and 4.1.2 ship with that version. When a request's Accept-Language header contains
more locales than the limit, HttpServletRequest.getLocale() / getLocales() throw an
IllegalArgumentException. This affects anything that resolves the request's locale, such
as Spring MVC's AcceptHeaderLocaleResolver.

We ran into this in production after upgrading: requests from browsers with many languages
configured started failing. The change is easy to miss, as Tomcat's changelog only describes
it as "Optimize Accept-Language header processing and use of resource bundles for
localization".

Other applications will likely need to change this limit as we did. It would be good if
they could do so with a property, rather than having to write a WebServerFactoryCustomizer.

Changes

  • Add server.tomcat.max-locale-count, following the approach taken for
    server.tomcat.max-part-count and server.tomcat.max-part-header-size (Upgrade to Tomcat 10.1.42 #45869).
  • The default is aligned with Tomcat's (10), and a value of less than 0 means no limit.
  • A NoSuchMethodError is ignored for Tomcat < 11.0.27.

Default value

I'd like your opinion on this. A request to change Tomcat's default back to -1 was
declined (apache/tomcat#1096), so the question is whether Spring Boot should keep Tomcat's
default or use its own:

  • 10 (align with Tomcat): consistent with max-part-count and max-part-header-size,
    and with the existing tests that check that property defaults match the connector defaults.
  • -1 (no limit): keeps the behavior from before Tomcat 11.0.27, so that a Spring Boot
    patch upgrade doesn't break applications that receive such requests.

I'm happy to update the PR to use -1 if you prefer.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. label Oct 23, 2026
@be-hase

be-hase commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

It looks like Tomcat has been updated to ignore locales beyond the maxLocaleCount limit.
apache/tomcat@c639c7e

This seems to make this PR somewhat less necessary, but I'll keep it open for now.

@philwebb

Copy link
Copy Markdown
Member

so the question is whether Spring Boot should keep Tomcat's
default or use its own:

Our default position is to align with Tomcat.

This seems to make this PR somewhat less necessary, but I'll keep it open for now.

I tempted to still offer a property in case users need the old behavior. It's probably possible to use a customizer, but the property is nicer IMO.

@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. labels Oct 26, 2026
@philwebb philwebb added this to the 4.0.x milestone Oct 26, 2026
@philwebb philwebb changed the title Add a property to configure Tomcat's maxLocaleCount Tomcat's new 'maxLocaleCount' property cannot be easily configured Oct 26, 2026
@be-hase

be-hase commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, @philwebb. I've kept the default aligned with Tomcat (10) and updated the property's description so that it's accurate both for Tomcat 11.0.27 (where exceeding the limit causes an IllegalArgumentException) and for the upcoming soft-fail behavior (apache/tomcat@c639c7e), where extra locales are ignored.

@wilkinsona wilkinsona self-assigned this Oct 27, 2026
Tomcat 11.0.27 has introduced a new connector attribute,
maxLocaleCount, that limits the number of locales parsed from a
request's Accept-Language header.

To ease its configuration, this commit introduces a
server.tomcat.max-locale-count property. The default is aligned with
that of Tomcat (10).

Signed-off-by: be-hase <hsb.1014@gmail.com>

See spring-projectsgh-52367
@wilkinsona
wilkinsona changed the base branch from main to 4.0.x October 27, 2026 09:17
@wilkinsona
wilkinsona force-pushed the tomcat-max-locale-count branch from e34cf1c to f05b9dc Compare October 27, 2026 09:18
@wilkinsona wilkinsona modified the milestones: 4.0.x, 4.0.10 Oct 27, 2026
@wilkinsona
wilkinsona merged commit e63f205 into spring-projects:4.0.x Oct 27, 2026
2 checks passed
@wilkinsona

Copy link
Copy Markdown
Member

Thanks, @be-hase.

@be-hase

be-hase commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants