Locale.getDefault bug in JDK 1.7

Discussion in 'Java' started by Roedy Green, Aug 22, 2011.

  1. Roedy Green

    Roedy Green Guest

    I noticed that Locale.getDefault is returning the wrong locale in JDK
    1.7. It used to work fine. It is not returning USA even though my OS
    is configured as Canada.

    Here is an SSCCE

    /*
    * [TestLocale.java]
    *
    * Summary: Get the Locale.
    *
    * Copyright: (c) 2011 Roedy Green, Canadian Mind Products,
    http://mindprod.com
    *
    * Licence: This software may be copied and used freely for any
    purpose but military.
    * http://mindprod.com/contact/nonmil.html
    *
    * Requires: JDK 1.7+
    *
    * Created with: JetBrains IntelliJ IDEA IDE
    http://www.jetbrains.com/idea/
    *
    * Version History:
    * 1.0 2011-08-21
    */
    package com.mindprod.example;

    import java.util.Locale;

    import static java.lang.System.out;

    /**
    * Get the Locale
    *
    * @author Roedy Green, Canadian Mind Products
    * @version 1.0 2011-08-21
    * @since 2011-08-21
    */
    public final class TestLocale
    {
    // -------------------------- STATIC METHODS
    --------------------------

    /**
    * display fields of a Locale
    *
    * @param l the Locale
    *
    * @desc description of the Locale
    */
    private static void showLocale( String desc, Locale l )
    {
    out.println( desc );
    out.println( "display:" + l.getDisplayName() );
    out.println( "country:" + l.getCountry() );
    out.println( "ISO3:" + l.getISO3Country() );
    out.println( "display country:" + l.getDisplayCountry() );
    out.println( "language:" + l.getLanguage() );
    out.println( "display language:" + l.getDisplayLanguage() );
    out.println();
    }

    // --------------------------- main() method
    ---------------------------

    /**
    * Display current Locale
    *
    * @param args not used
    */
    public static void main( String[] args )
    {
    // Four ways to get a Locale

    Locale defaultLocale = Locale.getDefault(); // browser/JVM
    default
    showLocale( "D E F A U L T", defaultLocale );

    Locale specifiedLocale = new Locale( "en", "US" ); //
    language/country
    showLocale( "N E W E N U S", specifiedLocale );

    Locale localeConstant = Locale.CANADA_FRENCH; // static final
    constants
    showLocale( "C A N A D A _ F R E N C H", localeConstant );

    // Locale serverLocale = request.getLocale(); // in a servlet
    to get remote user's locale
    }
    }

    D E F A U L T
    display:English (United States)
    country:US
    ISO3:USA
    display country:United States
    language:en
    display language:English

    N E W E N U S
    display:English (United States)
    country:US
    ISO3:USA
    display country:United States
    language:en
    display language:English

    C A N A D A _ F R E N C H
    display:French (Canada)
    country:CA
    ISO3:CAN
    display country:Canada
    language:fr
    display language:French

    I wonder if someone with a non-US locale could try this. I would like
    to know if the problem is with my copy of Windows 7 64-bit or with my
    copy of the JDK.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    The modern conservative is engaged in one of man's oldest exercises in moral philosophy; that is,
    the search for a superior moral justification for selfishness.
    ~ John Kenneth Galbraith (born: 1908-10-15 died: 2006-04-29 at age: 97)
    Roedy Green, Aug 22, 2011
    #1
    1. Advertising

  2. Roedy Green

    Roedy Green Guest

    Re: Why does Eclipse find error in simple "public static void main( String[] args) { } instruction?

    On 21 Aug 2011 17:41:53 GMT, (Gianni Galore) wrote,
    quoted or indirectly quoted someone who said :

    >package aaa.bbb;
    >
    >public static void main( String[] args) {
    > System.out.println("hello");
    > }
    >
    >


    It is best to post everything. The problem most often is in the stuff
    you don't post, in this case your class definition.

    see http://mindprod.com/jgloss/helloworld.html
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    The modern conservative is engaged in one of man's oldest exercises in moral philosophy; that is,
    the search for a superior moral justification for selfishness.
    ~ John Kenneth Galbraith (born: 1908-10-15 died: 2006-04-29 at age: 97)
    Roedy Green, Aug 22, 2011
    #2
    1. Advertising

  3. Roedy Green

    Roedy Green Guest

    On Sun, 21 Aug 2011 23:56:01 -0700, Roedy Green
    <> wrote, quoted or indirectly quoted
    someone who said :

    >I noticed that Locale.getDefault is returning the wrong locale in JDK
    >1.7. It used to work fine. It is not returning USA even though my OS
    >is configured as Canada.


    I tried reinstalling windows 7 64 bit. The bug is still there.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    The modern conservative is engaged in one of man's oldest exercises in moral philosophy; that is,
    the search for a superior moral justification for selfishness.
    ~ John Kenneth Galbraith (born: 1908-10-15 died: 2006-04-29 at age: 97)
    Roedy Green, Aug 22, 2011
    #3
  4. Roedy Green

    Lew Guest

    Re: Why does Eclipse find error in simple "public static void main(String[] args) { } instruction?

    Patricia Shanahan wrote:
    > Roedy Green wrote:
    >> Gianni Galore wrote, quoted or indirectly quoted someone who said :
    >>> package aaa.bbb;
    >>>
    >>> public static void main( String[] args) {
    >>> System.out.println("hello");
    >>> }

    >>
    >> It is best to post everything. The problem most often is in the stuff
    >> you don't post, in this case your class definition.
    >>
    >> see http://mindprod.com/jgloss/helloworld.html

    >
    > I think he did post the whole thing, and there is no class declaration.
    >
    > The compiler seems to be totally confused, which would be consistent
    > with that. It would not even be considering a method declaration. It
    > looks as though its last try was to parse it as an annotation, which can
    > appear before the first class declaration.


    Confusingly, at least via Google Groups here, these last two posts appeared in a thread entitled "Locale.getDefault bug in JDK 1.7". Is this just on my end?

    The original post that described a bug due to a missing class declaration was answered in its own thread pretty well already.

    --
    Lew
    Lew, Aug 22, 2011
    #4
  5. Roedy Green

    Roedy Green Guest

    Re: Why does Eclipse find error in simple "public static void main( String[] args) { } instruction?

    On Mon, 22 Aug 2011 09:15:29 -0700, Peter Duniho
    <> wrote, quoted or indirectly quoted
    someone who said :

    >
    >I don't know how he does it.


    I think what you have to do is post WHILE you are still reading
    messages.

    Now has anything to report on the JDK 1.7 Locale.getDefault bug?
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    The modern conservative is engaged in one of man's oldest exercises in moral philosophy; that is,
    the search for a superior moral justification for selfishness.
    ~ John Kenneth Galbraith (born: 1908-10-15 died: 2006-04-29 at age: 97)
    Roedy Green, Aug 22, 2011
    #5
  6. Roedy Green

    markspace Guest

    Re: Why does Eclipse find error in simple "public static void main(String[] args) { } instruction?

    On 8/22/2011 8:56 AM, Lew wrote:

    > Confusingly, at least via Google Groups here, these last two posts
    > appeared in a thread entitled "Locale.getDefault bug in JDK 1.7". Is
    > this just on my end?



    No, my Thunderbird is seeing the mix up as well.
    markspace, Aug 22, 2011
    #6
  7. Roedy Green

    markspace Guest

    Re: Why does Eclipse find error in simple "public static void main(String[] args) { } instruction?

    On 8/22/2011 10:02 AM, Roedy Green wrote:

    > Now has anything to report on the JDK 1.7 Locale.getDefault bug?



    If anyone does, could you post it to the original post? This thread has
    devolved into off-top discussion for locale issues.
    markspace, Aug 22, 2011
    #7
  8. Roedy Green

    markspace Guest

    On 8/21/2011 11:56 PM, Roedy Green wrote:
    > I noticed that Locale.getDefault is returning the wrong locale in JDK
    > 1.7. It used to work fine. It is not returning USA even though my OS
    > is configured as Canada.



    I'm confused. It is *NOT* returning USA? Even though your OS is set to CA?

    What do you expect it to return?
    markspace, Aug 22, 2011
    #8
  9. markspace <-@> wrote:
    > On 8/21/2011 11:56 PM, Roedy Green wrote:
    >> I noticed that Locale.getDefault is returning the wrong locale in JDK
    >> 1.7. It used to work fine. It is not returning USA even though my OS
    >> is configured as Canada.

    > I'm confused. It is *NOT* returning USA? Even though your OS is set to CA?
    > What do you expect it to return?


    My brain "auto-corrected" it: "not" -> "now"

    I haven't yet installed JDK 1.7, though...
    Andreas Leitgeb, Aug 22, 2011
    #9
  10. Roedy Green

    Lew Guest

    markspace wrote:
    > Roedy Green wrote:
    >> I noticed that Locale.getDefault is returning the wrong locale in JDK
    >> 1.7. It used to work fine. It is not returning USA even though my OS
    >> is configured as Canada.


    [context restoration]
    >> D E F A U L T
    >> display:English (United States)
    >> country:US
    >> ISO3:USA
    >> display country:United States
    >> language:en
    >> display language:English

    ....
    >
    > I'm confused. It is *NOT* returning USA? Even though your OS is set to CA?
    >
    > What do you expect it to return?


    Roedy's output shows that the locale default is US. However, it doesn't show how he thinks the OS is set to CA; presumably it's set in his BIOS or other low-level. I'd like to see Roedy's program expanded to show the results of 'getDefault()' after a 'setDefault()' to Canada. I'd also like to seethe values of the OS's LANG and LANGUAGE envars, or equivalents. Finally,I'd like to see what Java has for the user.language, user.country, and user.variant system properties.

    --
    Lew
    Lew, Aug 22, 2011
    #10
  11. Roedy Green

    Lew Guest

    <sscce source="tryout/Localizer.java">
    package tryout;

    import java.util.Locale;

    /**
    * Try out Locale tricks.
    * Invocations to try:
    * java tryout.Localizer
    * java -Duser.language=fr tryout.Localizer
    * java -Duser.language=fr -Duser.country=CA tryout.Localizer
    */
    public class Localizer {
    /** main method.
    * @param args String [] arguments.
    */
    public static void main(String [] args) {
    System.out.println("");
    System.out.println("user.language = " + System.getProperty("user.language"));
    System.out.println(" user.country = " + System.getProperty("user.country"));
    System.out.println(" user.variant = " + System.getProperty("user.variant"));

    System.out.println("");
    System.out.println("default");
    display(Locale.getDefault());

    System.out.println("");
    System.out.println("Set default to CANADA");
    Locale.setDefault(Locale.CANADA);
    display(Locale.getDefault());

    System.out.println("");
    System.out.println("Set default to FRANCE");
    Locale.setDefault(Locale.FRANCE);
    display(Locale.getDefault());

    System.out.println("");
    System.out.println("Set default to CANADA_FRENCH");
    Locale.setDefault(Locale.CANADA_FRENCH);
    display(Locale.getDefault());

    System.out.println("");
    System.out.println("Display CANADA");
    display(Locale.CANADA);

    System.out.println("");
    System.out.println("Display FRANCE");
    display(Locale.FRANCE);

    System.out.println("");
    System.out.println("Display CANADA_FRENCH");
    display(Locale.CANADA_FRENCH);

    }

    private static void display(Locale locale) {
    System.out.println("Locale = " + locale.toString()
    + " language = \"" + locale.getLanguage() + "\" country = \""
    + locale.getCountry() + "\" variant = \"" + locale.getVariant() + "\"");
    }
    }
    </sscce>
    Lew, Aug 22, 2011
    #11
  12. Roedy Green

    Roedy Green Guest

    On Mon, 22 Aug 2011 10:51:53 -0700, markspace <-@.> wrote, quoted or
    indirectly quoted someone who said :

    >It is not returning USA even though my OS
    >> is configured as Canada.

    >
    >
    >I'm confused. It is *NOT* returning USA? Even though your OS is set to CA?
    >
    >What do you expect it to return?


    Blast. That is a DSK typo I meant to write
    >It is noW returning USA even though my OS
    >> is configured as Canada.


    One of the disadvantages of the DSK layout, with common letters close
    to each other, is typos become valid words rather than gibberish.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    The modern conservative is engaged in one of man's oldest exercises in moral philosophy; that is,
    the search for a superior moral justification for selfishness.
    ~ John Kenneth Galbraith (born: 1908-10-15 died: 2006-04-29 at age: 97)
    Roedy Green, Aug 23, 2011
    #12
  13. Roedy Green

    Silvio Guest

    On 08/23/2011 05:08 PM, Roedy Green wrote:
    > On Mon, 22 Aug 2011 10:51:53 -0700, markspace<-@.> wrote, quoted or
    > indirectly quoted someone who said :
    >
    >> It is not returning USA even though my OS
    >>> is configured as Canada.

    >>
    >>
    >> I'm confused. It is *NOT* returning USA? Even though your OS is set to CA?
    >>
    >> What do you expect it to return?

    >
    > Blast. That is a DSK typo I meant to write
    >> It is noW returning USA even though my OS
    >>> is configured as Canada.

    >
    > One of the disadvantages of the DSK layout, with common letters close
    > to each other, is typos become valid words rather than gibberish.


    Dominique Strauss-Kahn? Whiskey Tango Foxtrot?
    Silvio, Aug 23, 2011
    #13
  14. Roedy Green

    Lew Guest

    Silvio wrote:
    > Roedy Green wrote:
    >> markspace<-@.> wrote, quoted or indirectly quoted someone who said :
    > >> It is not returning USA even though my OS
    >>>> is configured as Canada.
    >>>
    >>>
    >>> I'm confused. It is *NOT* returning USA? Even though your OS is set to CA?
    >>>
    >>> What do you expect it to return?

    >>
    >> Blast. That is a DSK typo I meant to write
    >>> It is noW returning USA even though my OS
    >>>> is configured as Canada.

    >>
    >> One of the disadvantages of the DSK layout, with common letters close
    >> to each other, is typos become valid words rather than gibberish.

    >
    > Dominique Strauss-Kahn? Whiskey Tango Foxtrot?


    Silvio: http://lmgtfy.com/?q=DSK keyboard

    --
    Lew
    Lew, Aug 23, 2011
    #14
  15. Roedy Green

    Roedy Green Guest

    On Mon, 22 Aug 2011 11:22:06 -0700 (PDT), Lew <>
    wrote, quoted or indirectly quoted someone who said :

    >
    >Roedy's output shows that the locale default is US. However, it doesn't sh=
    >ow how he thinks the OS is set to CA; presumably it's set in his BIOS or ot=
    >her low-level. I'd like to see Roedy's program expanded to show the result=
    >s of 'getDefault()' after a 'setDefault()' to Canada. I'd also like to see=
    > the values of the OS's LANG and LANGUAGE envars, or equivalents. Finally,=
    > I'd like to see what Java has for the user.language, user.country, and use=
    >r.variant system properties.



    I have windows 7 64 bit. I set the country and language in the control
    panel. Windows does not export user.country and user.language to the
    set environment. You have to get at it programmatically.

    Here is the SSCCE with the changes you requested. It works ok with JDK
    1.6 but not 1.7 on Windows 7 64 bit.

    To see the problem, configure your windows 7 to a country something
    other than USA, then run this SSCCE under JDK 1.7 (and perhaps other
    combinations).

    /*
    * [TestLocale.java]
    *
    * Summary: Get the Locale.
    *
    * Copyright: (c) 2011 Roedy Green, Canadian Mind Products,
    http://mindprod.com
    *
    * Licence: This software may be copied and used freely for any
    purpose but military.
    * http://mindprod.com/contact/nonmil.html
    *
    * Requires: JDK 1.7+
    *
    * Created with: JetBrains IntelliJ IDEA IDE
    http://www.jetbrains.com/idea/
    *
    * Version History:
    * 1.0 2011-08-21
    */
    package com.mindprod.example;

    import java.util.Locale;

    import static java.lang.System.out;

    /**
    * Display the Locale
    *
    * @author Roedy Green, Canadian Mind Products
    * @version 1.1 2011-08-23 add Lew Bloch's requested extensions,
    display of user.country and setDefault.
    * @since 2011-08-21
    */
    public final class TestLocale
    {
    // -------------------------- STATIC METHODS
    --------------------------

    /**
    * display fields of a Locale
    *
    * @param l the Locale
    * @param desc description of the Locale
    */
    private static void showLocale( String desc, Locale l )
    {
    out.println( desc );
    out.println( "display:" + l.getDisplayName() );
    out.println( "country:" + l.getCountry() );
    out.println( "ISO3:" + l.getISO3Country() );
    out.println( "display country:" + l.getDisplayCountry() );
    out.println( "language:" + l.getLanguage() );
    out.println( "display language:" + l.getDisplayLanguage() );
    out.println( "user.country:" + System.getProperty(
    "user.country", "n/a" ) );
    out.println( "user.language:" + System.getProperty(
    "user.language", "n/a" ) );
    out.println();
    }

    // --------------------------- main() method
    ---------------------------

    /**
    * Display current Locale
    *
    * @param args not used
    */
    public static void main( String[] args )
    {
    // various ways to get a Locale

    // demonstrates bugs in Windows 7 64-bit JDK 1.7 when country
    is configured in control panel as Canada.
    // user.country reports as US instead of CA
    // Locale.getDefault.getCountry() reports US instead of CA

    Locale defaultLocale = Locale.getDefault(); // browser/JVM
    default
    showLocale( "D E F A U L T", defaultLocale );

    Locale specifiedLocale = new Locale( "en", "US" ); //
    language/country
    showLocale( "N E W E N U S", specifiedLocale );

    Locale localeConstant = Locale.CANADA_FRENCH; // static final
    constants
    showLocale( "C A N A D A _ F R E N C H", localeConstant );

    Locale.setDefault( Locale.CANADA );
    Locale forcedDefault = Locale.getDefault();
    showLocale( "F O R C E D D E F A U L T", forcedDefault );

    // Locale serverLocale = request.getLocale(); // in a servlet
    to get remote user's locale
    }
    }


    Results from TestLocale

    D E F A U L T
    display:English (United States) <-- should be Canada when country
    configured as Canada in the control panel
    country:US
    ISO3:USA
    display country:United States
    language:en
    display language:English
    user.country:US <-- should be Canada
    user.language:en

    N E W E N U S
    display:English (United States)
    country:US
    ISO3:USA
    display country:United States
    language:en
    display language:English
    user.country:US
    user.language:en

    C A N A D A _ F R E N C H
    display:French (Canada)
    country:CA
    ISO3:CAN
    display country:Canada
    language:fr
    display language:French
    user.country:US
    user.language:en

    F O R C E D D E F A U L T
    display:English (Canada)
    country:CA
    ISO3:CAN
    display country:Canada
    language:en
    display language:English
    user.country:US <-- should be Canada
    user.language:en

    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    The modern conservative is engaged in one of man's oldest exercises in moral philosophy; that is,
    the search for a superior moral justification for selfishness.
    ~ John Kenneth Galbraith (born: 1908-10-15 died: 2006-04-29 at age: 97)
    Roedy Green, Aug 23, 2011
    #15
  16. Roedy Green

    Roedy Green Guest

    On Tue, 23 Aug 2011 09:04:48 -0700, Roedy Green
    <> wrote, quoted or indirectly quoted
    someone who said :

    >/*
    > * [TestLocale.java]
    > *
    > * Summary: Get the Locale.


    This program is posted at http://mindprod.com/jgloss/locale.html

    It is easier to read there since lines are not broken.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    The modern conservative is engaged in one of man's oldest exercises in moral philosophy; that is,
    the search for a superior moral justification for selfishness.
    ~ John Kenneth Galbraith (born: 1908-10-15 died: 2006-04-29 at age: 97)
    Roedy Green, Aug 23, 2011
    #16
  17. Roedy Green

    Roedy Green Guest

    On Sun, 21 Aug 2011 23:56:01 -0700, Roedy Green
    <> wrote, quoted or indirectly quoted
    someone who said :

    >I noticed that Locale.getDefault is returning the wrong locale in JDK
    >1.7. It used to work fine. It is not returning USA even though my OS
    >is configured as Canada.


    I reported it as an official bug. Sun said it has not been reported
    before.
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7082429.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    The modern conservative is engaged in one of man's oldest exercises in moral philosophy; that is,
    the search for a superior moral justification for selfishness.
    ~ John Kenneth Galbraith (born: 1908-10-15 died: 2006-04-29 at age: 97)
    Roedy Green, Aug 23, 2011
    #17
  18. Roedy Green

    Silvio Guest

    Silvio, Aug 23, 2011
    #18
  19. Roedy Green

    Arne Vajhøj Guest

    Re: Why does Eclipse find error in simple "public static void main(String[] args) { } instruction?

    On 8/22/2011 1:02 PM, Roedy Green wrote:
    > On Mon, 22 Aug 2011 09:15:29 -0700, Peter Duniho
    > <> wrote, quoted or indirectly quoted
    > someone who said :
    >> I don't know how he does it.

    >
    > I think what you have to do is post WHILE you are still reading
    > messages.


    Type less and think more!

    Arne
    Arne Vajhøj, Aug 24, 2011
    #19
  20. Roedy Green

    Lew Guest

    Silvio wrote:
    > Lew wrote:
    > > Silvio:http://lmgtfy.com/?q=DSK keyboard

    >
    > Lew: http://lmgtfy.com/?q=DSK


    Do you think you are being sufficiently disingenuous there, Silvio?

    It's obvious from the context that Roedy was talking about typing and key positions.

    It's equally obvious to me that you were being deliberately disingenuous in your response to Roedy.

    Is that really the best way for you to contribute to this newsgroup?

    --
    Lew
    Lew, Aug 24, 2011
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hariharan.A
    Replies:
    0
    Views:
    1,729
    Hariharan.A
    Feb 25, 2004
  2. Maurice Hulsman
    Replies:
    1
    Views:
    1,830
    Guus Bosman
    Jul 25, 2004
  3. Replies:
    4
    Views:
    993
  4. Gabriel Genellina
    Replies:
    0
    Views:
    690
    Gabriel Genellina
    Feb 18, 2009
  5. zade
    Replies:
    1
    Views:
    597
    James Kanze
    Mar 5, 2010
Loading...

Share This Page