commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rob Tompkins (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (TEXT-64) Investigate locale issue in ExtendedMessageFormatTest
Date Mon, 27 Feb 2017 13:22:45 GMT

    [ https://issues.apache.org/jira/browse/TEXT-64?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15885774#comment-15885774
] 

Rob Tompkins commented on TEXT-64:
----------------------------------

We are comparing the results from {{java.text.MessageFormat}} with those from {{org.apache.commons.text.ExtendedMessageFormat}},
and there are slight differences when calling {{Locale.getDefault}}. Namely:

{code:java}
public MessageFormat(String pattern) {
    this.locale = Locale.getDefault(Locale.Category.FORMAT);
    applyPattern(pattern);
}
{code}

versus

{code:java}
public ExtendedMessageFormat(final String pattern) {
    this(pattern, Locale.getDefault());
}
{code}

The key differences here in the {{Locale}} class reside in the {{initDefault}} method:

{code:java}
private static Locale initDefault() {
    String language, region, script, country, variant;
    language = AccessController.doPrivileged(
        new GetPropertyAction("user.language", "en"));
    // for compatibility, check for old user.region property
    region = AccessController.doPrivileged(
        new GetPropertyAction("user.region"));
    if (region != null) {
        // region can be of form country, country_variant, or _variant
        int i = region.indexOf('_');
        if (i >= 0) {
            country = region.substring(0, i);
            variant = region.substring(i + 1);
        } else {
            country = region;
            variant = "";
        }
        script = "";
    } else {
        script = AccessController.doPrivileged(
            new GetPropertyAction("user.script", ""));
        country = AccessController.doPrivileged(
            new GetPropertyAction("user.country", ""));
        variant = AccessController.doPrivileged(
            new GetPropertyAction("user.variant", ""));
    }

    return getInstance(language, script, country, variant, null);
}

private static Locale initDefault(Locale.Category category) {
    return getInstance(
        AccessController.doPrivileged(
            new GetPropertyAction(category.languageKey, defaultLocale.getLanguage())),
        AccessController.doPrivileged(
            new GetPropertyAction(category.scriptKey, defaultLocale.getScript())),
        AccessController.doPrivileged(
            new GetPropertyAction(category.countryKey, defaultLocale.getCountry())),
        AccessController.doPrivileged(
            new GetPropertyAction(category.variantKey, defaultLocale.getVariant())),
        null);
}
{code}

I suppose we could add the {{Locale.Category}} to the default locale creation, but as I'm
unfamiliar with the mechanics here I plan to bubble this up to the ML.

> Investigate locale issue in ExtendedMessageFormatTest
> -----------------------------------------------------
>
>                 Key: TEXT-64
>                 URL: https://issues.apache.org/jira/browse/TEXT-64
>             Project: Commons Text
>          Issue Type: Bug
>    Affects Versions: 1.0-beta-1
>            Reporter: Rob Tompkins
>             Fix For: 1.0
>
>
> During release testing, Bruno found the following problem, needing investigation, (http://markmail.org/message/hhio4ye2xlvdznlv).
> /* --- snip -- */
> Results :
> {code}
> Failed tests: 
> ExtendedMessageFormatTest.testBuiltInChoiceFormat:211->checkBuiltInFormat:336->checkBuiltInFormat:347->checkBuiltInFormat:376
> format Pattern=[1234.5: {0,choice,1#One|2#Two|3#Many {0,number}}], locale=[null]
> expected:<1234.5: Many 1[.234,]5> but was:<1234.5: Many 1[,234.]5>
> ExtendedMessageFormatTest.testBuiltInDateTimeFormat:230->checkBuiltInFormat:336->checkBuiltInFormat:347->checkBuiltInFormat:376
> format Pattern=[1: {0,date,short}], locale=[null] expected:<1: [23/01]/07> but
> was:<1: [1/23]/07>
> ExtendedMessageFormatTest.testBuiltInNumberFormat:277->checkBuiltInFormat:336->checkBuiltInFormat:347->checkBuiltInFormat:376
> format Pattern=[1: {0,number}], locale=[null] expected:<1: 6[.543,]21> but
> was:<1: 6[,543.]21>
> ExtendedMessageFormatTest.testExtendedAndBuiltInFormats:141 null expected:<Name:
> JOHN DOE DOB: [23/01/07 Salary: R$ 12.345,]67> but was:<Name: JOHN DOE DOB:
> [1/23/07 Salary: $12,345.]67>
> ExtendedMessageFormatTest.testOverriddenBuiltinFormat:253->checkBuiltInFormat:347->checkBuiltInFormat:376
> format Pattern=[1: {0,date}], locale=[null] expected:<1: [23/01/]2007> but
> was:<1: [Jan 23, ]2007>
> Tests run: 476, Failures: 5, Errors: 0, Skipped: 0
> [INFO] ------------------------------------------------------------------------
> [INFO] BUILD FAILURE
> [INFO] ------------------------------------------------------------------------
> [INFO] Total time: 11.385 s
> [INFO] Finished at: 2017-02-06T14:07:52-02:00
> [INFO] Final Memory: 30M/328M
> [INFO] ------------------------------------------------------------------------
> {code}
> /* --- snip -- */
> Here's my env:
> Apache Maven 3.3.9
> Maven home: /usr/share/maven
> Java version: 1.8.0_111, vendor: Oracle Corporation
> Java home: /usr/lib/jvm/java-8-oracle/jre
> Default locale: en_US, platform encoding: UTF-8
> OS name: "linux", version: "4.4.0-59-generic", arch: "amd64", family: "unix"
> Even though the JVM locale seems to be set to en_US, I'm in Brazil right now
> with the time in Ubuntu set to local time, as well as the locale (or so I
> think). Here's my output of running the `locale` command.
> /* --- snip --- */
> $ locale
> LANG=en_US.UTF-8
> LANGUAGE=en_US
> LC_CTYPE=pt_BR.UTF-8
> LC_NUMERIC=pt_BR.UTF-8
> LC_TIME=pt_BR.UTF-8
> LC_COLLATE="en_US.UTF-8"
> LC_MONETARY=pt_BR.UTF-8
> LC_MESSAGES="en_US.UTF-8"
> LC_PAPER=pt_BR.UTF-8
> LC_NAME=pt_BR.UTF-8
> LC_ADDRESS=pt_BR.UTF-8
> LC_TELEPHONE=pt_BR.UTF-8
> LC_MEASUREMENT=pt_BR.UTF-8
> LC_IDENTIFICATION=pt_BR.UTF-8
> LC_ALL=
> /* --- snip --- */



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message