Skip to content

Better handling of illegal locale values in LocaleChangeInterceptor [SPR-9456] #14091

Closed

Description

@spring-projects-issues

Kaj Hejer opened SPR-9456 and commented

When url contains illegal values for locale in the lang parameter like

http://www.myhost.com/index.html?lang=en-

LocaleChangeInterceptor throws an exception:

java.lang.IllegalArgumentException: Locale value "no-" contains invalid characters
        at org.springframework.util.StringUtils.parseLocaleString(StringUtils.java:671)
        at org.springframework.web.servlet.i18n.LocaleChangeInterceptor.preHandle(LocaleChangeInterceptor.java:73)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:781)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:574)
        at javax.servlet.http.HttpServlet.doHead(HttpServlet.java:238)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:117)

Maybe a better solution is to catch this exception in LocaleChangeInterceptor and just write a logmessage.


Affects: 3.1 GA

Issue Links:

1 votes, 5 watchers

Activity

  1. spring-projects-issues commented on Feb 6, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Christian Gendreau commented

    Is there a way to by pass this issue without extending LocaleChangeInterceptor ?
    This issue makes it hard to recover from a simple wrong query parameter.

    Thanks

  2. spring-projects-issues commented on Sep 21, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    Will take a look at this for 4.2.2.

  3. spring-projects-issues commented on Sep 23, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    I've added an "ignoreInvalidLocale" property to LocaleChangeInterceptor, catching such an IllegalArgumentException and logging its message at debug level instead of propagating it.

    Juergen

  4. added
    type: enhancement
    in: web
    on Jan 11, 2019
  5. added this to the 4.2.2 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webtype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions