Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.5.10
    • Fix Version/s: 2.5.12
    • Component/s: Core
    • Labels:
      None

      Description

      < 2.5.11 calling empty locale ?request_locale= results in locale en

      In 2.5.11 calling empty locale ?request_locale= results in locale object (not null) with property languageTag set to null and as language == empty

      NB: it is also interesting to see the different behaviours for

      wget --header="Accept-Language: fff" --no-check-certificate https://localhost:8443/myProject/path
      
      "Accept-Language: ff" => Fula language
      "Accept-Language: fff" => empty locale
      "Accept-Language: ffff" => exception thrown
      

      This seems to be the standard behaviour of Locale though.

        Activity

        Hide
        lukaszlenart Lukasz Lenart added a comment - - edited

        I cannot reproduce this issue, by an empty string you meant {{ }} or did you add ''?

        Show
        lukaszlenart Lukasz Lenart added a comment - - edited I cannot reproduce this issue, by an empty string you meant {{ }} or did you add '' ?
        Hide
        flyingfischer Markus Fischer added a comment -

        Just did a recheck:

        2.5.11, calling:

        request_locale= (empty, no space, no quotation marks) will lead to an empty locale.
        request_locale='' (quotation marks as invalid, language) will lead to en.
        request_locale=djkjfkjsgkjgk will lead to en

        Show
        flyingfischer Markus Fischer added a comment - Just did a recheck: 2.5.11, calling: request_locale= (empty, no space, no quotation marks) will lead to an empty locale. request_locale='' (quotation marks as invalid, language) will lead to en. request_locale=djkjfkjsgkjgk will lead to en
        Hide
        flyingfischer Markus Fischer added a comment -

        To be more precise:

        After calling request_locale= (empty, no space, no quotation marks) the language used in the project is still en. What did change in 2.5.11 is this:

                     <s:if test='#request.locale.language=="en"'>
        			 <li class="active"><s:a href="?request_locale=en">EN</s:a></li>
                     </s:if>
        

        In 2.5.10.1 this would be a highlighted/active element, where in 2.5.11 this is inactive. So the property behind request.locale.language has changed from en to something else.

        Show
        flyingfischer Markus Fischer added a comment - To be more precise: After calling request_locale= (empty, no space, no quotation marks) the language used in the project is still en. What did change in 2.5.11 is this: <s: if test='#request.locale.language== "en" '> <li class= "active" ><s:a href= "?request_locale=en" >EN</s:a></li> </s: if > In 2.5.10.1 this would be a highlighted/active element, where in 2.5.11 this is inactive. So the property behind request.locale.language has changed from en to something else.
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        Can you use <s:property value="#request.locale.language"/>? because it works for me.

        Show
        lukaszlenart Lukasz Lenart added a comment - Can you use <s:property value="#request.locale.language"/> ? because it works for me.
        Hide
        flyingfischer Markus Fischer added a comment - - edited

        I already tested this:

        <s:property value="#request.locale.language"/> prints the appropriate language code, and '' (empty / no value) for request_locale=. This sounds logically, but seems to be a different beaviour from 2.5.10.1.

        What is the output for <s:property value="#request.locale.language"/> and request_locale= in your setup?

        Do debug this issue in 2.5.10.1, I'd need to revert some changes. But I still have the application online running, which shows a highligted EN element for request_locale=. So <s:if test='#request.locale.language=="en"'> seems to evaluate to true for request_locale=.

        In Any case it's easy to work around...

        Show
        flyingfischer Markus Fischer added a comment - - edited I already tested this: <s:property value="#request.locale.language"/> prints the appropriate language code, and '' (empty / no value) for request_locale= . This sounds logically, but seems to be a different beaviour from 2.5.10.1. What is the output for <s:property value="#request.locale.language"/> and request_locale= in your setup? Do debug this issue in 2.5.10.1, I'd need to revert some changes. But I still have the application online running, which shows a highligted EN element for request_locale= . So <s:if test='#request.locale.language=="en"'> seems to evaluate to true for request_locale= . In Any case it's easy to work around...
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        It shows en - default locale for my Mac, even for empty string.

        Do you use JDK7 or JDK8?
        Browser?

        Show
        lukaszlenart Lukasz Lenart added a comment - It shows en - default locale for my Mac, even for empty string. Do you use JDK7 or JDK8? Browser?
        Hide
        yasser.zamani Yasser Zamani added a comment -

        I could not re-produce. I tested `?request_locale=` , `?request_locale=''` and `?request_locale=""`. All works redirecting to default locale with Struts 2.5.11. Same for `ff` , `fff` and `ffff`. I did not get any exception.

        Show
        yasser.zamani Yasser Zamani added a comment - I could not re-produce. I tested `?request_locale=` , `?request_locale=''` and `?request_locale=""`. All works redirecting to default locale with Struts 2.5.11. Same for `ff` , `fff` and `ffff`. I did not get any exception.
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        Yasser Zamani for ffff you will get a WARN in logs.

        Show
        lukaszlenart Lukasz Lenart added a comment - Yasser Zamani for ffff you will get a WARN in logs.
        Hide
        flyingfischer Markus Fischer added a comment -

        I use JDK 8 / Linux / FF 54.

        Show
        flyingfischer Markus Fischer added a comment - I use JDK 8 / Linux / FF 54.
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        Reproduced Now I have to debug it

        Show
        lukaszlenart Lukasz Lenart added a comment - Reproduced Now I have to debug it
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        It's all about JDK8, in JDK8 an empty locale string is a valid locale

        Show
        lukaszlenart Lukasz Lenart added a comment - It's all about JDK8, in JDK8 an empty locale string is a valid locale
        Hide
        flyingfischer Markus Fischer added a comment -

        Great! I just reverted to 2.5.10.1 and still confirm it. There is one difference though:

        In FF I did remove a plugin which interfers with user-agent and languages. Then reset FF to normal language de in my case. Now 2.5.10 show de with request_locale=, picking up the browser default locale and <s:property value="#request.locale.language"/> will print de, while 2.5.11 will answer <s:property value="#request.locale.language"/> with ''.

        Show
        flyingfischer Markus Fischer added a comment - Great! I just reverted to 2.5.10.1 and still confirm it. There is one difference though: In FF I did remove a plugin which interfers with user-agent and languages. Then reset FF to normal language de in my case. Now 2.5.10 show de with request_locale= , picking up the browser default locale and <s:property value="#request.locale.language"/> will print de , while 2.5.11 will answer <s:property value="#request.locale.language"/> with ''.
        Hide
        flyingfischer Markus Fischer added a comment -

        Wow! You are really quick!

        Show
        flyingfischer Markus Fischer added a comment - Wow! You are really quick!
        Hide
        lukaszlenart Lukasz Lenart added a comment - - edited

        LANG-941 and https://stackoverflow.com/questions/14088874/java-util-locale-has-an-empty-first-item

        and now there is a question: should we change this behaviour?

        Show
        lukaszlenart Lukasz Lenart added a comment - - edited LANG-941 and https://stackoverflow.com/questions/14088874/java-util-locale-has-an-empty-first-item and now there is a question: should we change this behaviour?
        Hide
        flyingfischer Markus Fischer added a comment -

        I am neutral on this. Maybe to consider:

        With an empty locale Struts will bring up the value for <s:text name="meyKey"/> in the default locale of the browser, while #request.locale.language evaluates to ''.

        Show
        flyingfischer Markus Fischer added a comment - I am neutral on this. Maybe to consider: With an empty locale Struts will bring up the value for <s:text name="meyKey"/> in the default locale of the browser, while #request.locale.language evaluates to ''.
        Hide
        flyingfischer Markus Fischer added a comment -

        One step further: it will be hard to workaround, when you do not know what locale <s:text name="meyKey"/> will deliver on request_locale=. The result may be in any language and you will not be able to know it by #request.locale.language. Things would be more consistent if <s:text name="meyKey"/> would fall back to the default locale defined in Struts.

        Show
        flyingfischer Markus Fischer added a comment - One step further: it will be hard to workaround, when you do not know what locale <s:text name="meyKey"/> will deliver on request_locale= . The result may be in any language and you will not be able to know it by #request.locale.language . Things would be more consistent if <s:text name="meyKey"/> would fall back to the default locale defined in Struts.
        Hide
        flyingfischer Markus Fischer added a comment -

        Even when we accept an empty locale to be a valid locale, we have further inconsistencies:

        request_locale=ffffff will fall back to the default locale defined in Struts.
        request_locale= will fall back to the default locale of the browser for, at least for <s:text name="myKey"/>

        Show
        flyingfischer Markus Fischer added a comment - Even when we accept an empty locale to be a valid locale, we have further inconsistencies: request_locale=ffffff will fall back to the default locale defined in Struts. request_locale= will fall back to the default locale of the browser for, at least for <s:text name="myKey"/>
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        I have a fix in place - I had written a test but I have been running it on JDK7 that's why I didn't catch that issue early

        Show
        lukaszlenart Lukasz Lenart added a comment - I have a fix in place - I had written a test but I have been running it on JDK7 that's why I didn't catch that issue early
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 67536bf2d2440256c9c46f9a6128cff0875629d6 in struts's branch refs/heads/master from Lukasz Lenart
        [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=67536bf ]

        WW-4810 Fixes issue with passing an empty locale on JDK8

        Show
        jira-bot ASF subversion and git services added a comment - Commit 67536bf2d2440256c9c46f9a6128cff0875629d6 in struts's branch refs/heads/master from Lukasz Lenart [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=67536bf ] WW-4810 Fixes issue with passing an empty locale on JDK8
        Hide
        hudson Hudson added a comment -

        SUCCESS: Integrated in Jenkins build Struts-JDK7-master #643 (See https://builds.apache.org/job/Struts-JDK7-master/643/)
        WW-4810 Fixes issue with passing an empty locale on JDK8 (lukaszlenart: rev 67536bf2d2440256c9c46f9a6128cff0875629d6)

        • (edit) core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java
        • (edit) core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java
        Show
        hudson Hudson added a comment - SUCCESS: Integrated in Jenkins build Struts-JDK7-master #643 (See https://builds.apache.org/job/Struts-JDK7-master/643/ ) WW-4810 Fixes issue with passing an empty locale on JDK8 (lukaszlenart: rev 67536bf2d2440256c9c46f9a6128cff0875629d6) (edit) core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java (edit) core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java
        Hide
        flyingfischer Markus Fischer added a comment -

        Thanks for keeping up so deeply on this corner case and the fix provided! Let me know, if I shall retest. Will there be new standalone artifacts? I am unfortunately not on maven.

        Show
        flyingfischer Markus Fischer added a comment - Thanks for keeping up so deeply on this corner case and the fix provided! Let me know, if I shall retest. Will there be new standalone artifacts? I am unfortunately not on maven.
        Hide
        lukaszlenart Lukasz Lenart added a comment - - edited

        Yes, there'll be a new version released ASAP, I'm waiting on your inputs regarding the FontAwesome issue

        Show
        lukaszlenart Lukasz Lenart added a comment - - edited Yes, there'll be a new version released ASAP, I'm waiting on your inputs regarding the FontAwesome issue
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        Resolved

        Show
        lukaszlenart Lukasz Lenart added a comment - Resolved

          People

          • Assignee:
            lukaszlenart Lukasz Lenart
            Reporter:
            flyingfischer Markus Fischer
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development