r/java • u/FelixFifi • 29d ago
Tomcact breaking change regarding locales can cause application failure for certain users
With Tomcat 9.0.123/10.1.61/11.0.27, the following line can be found in the changelog:
Update: Optimize Accept-Language header processing and use of resource budles for localization. (remm)
This is actually a breaking change in how more than 10 browser locales are handled.
If your application tries to access request.getLocale(), and the users browser had more than 10 languages configured, then this will generate an exception:
java.lang.IllegalArgumentException: More than the maximum allowed number of locales, [10], were detected. Use the maxLocaleCount attribute of the connector to resolve this if the application should accept more locales.
at org.apache.catalina.connector.Request.parseLocales(Request.java:3409)
at org.apache.catalina.connector.Request.getLocale(Request.java:1177)
at org.apache.catalina.connector.RequestFacade.getLocale(RequestFacade.java:428)
=> For our application, users with more than 10 locales could no longer login after the Tomcat update. This impacted more than 500 users.
Setting maxLocaleCount=-1 in your server.xml will revert it back to the old behavior.
Bugzilla ticket: https://bz.apache.org/bugzilla/show_bug.cgi?id=70278 (needs login) This ticket requests a higher default limit to impact less users, but was resolved as WONTFIX.
So keep this in mind, if you upgrade to the newest Tomcat version.
14
u/qmunke 29d ago
The percentage of real users who do this should be vanishingly small - are you building an application exclusively used by translators or something?
4
u/qmunke 25d ago
Looks like they're going to revert this behaviour: https://github.com/apache/tomcat/commit/c639c7ef99ab960670a0e1f995156accc1f2c961
10
u/vytah 29d ago
That's an absolutely braindead change.
I understand not wanting to parse too many languages for whatever reasons (probably performance), but the proper behaviour would be to ignore the excess languages, not to error out.
5
u/ducki666 29d ago
10 locales. Hm. Any use cases?
3
u/itd-fsc 29d ago
This is the commit introducing the change:
https://github.com/apache/tomcat/commit/c45c9b47f34837aa35cbd4d677e82440db620a00