Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #7312

Re: Locale.getDefault bug in JDK 1.7

From Roedy Green <see_website@mindprod.com.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Locale.getDefault bug in JDK 1.7
Date 2011-08-23 09:04 -0700
Organization Canadian Mind Products
Message-ID <plg757tav9tjtv96od45ll38b3dhvjqavs@4ax.com> (permalink)
References <k4u357dqe5lejh08eiadvd2ad2kji1ivho@4ax.com> <j2u503$ai1$3@dont-email.me> <dfb5840e-45d2-4ac6-9dfd-db7c4e4b6cf9@glegroupsg2000goo.googlegroups.com>

Show all headers | View raw


On Mon, 22 Aug 2011 11:22:06 -0700 (PDT), Lew <lewbloch@gmail.com>
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) 

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Locale.getDefault bug in JDK 1.7 Roedy Green <see_website@mindprod.com.invalid> - 2011-08-21 23:56 -0700
  Re: Why does Eclipse find error in simple "public static void main( String[] args) { } instruction? Roedy Green <see_website@mindprod.com.invalid> - 2011-08-21 23:58 -0700
    Re: Why does Eclipse find error in simple "public static void main( String[] args) { } instruction? Patricia Shanahan <pats@acm.org> - 2011-08-22 08:37 -0700
      Re: Why does Eclipse find error in simple "public static void main( String[] args) { } instruction? Lew <lewbloch@gmail.com> - 2011-08-22 08:56 -0700
        Re: Why does Eclipse find error in simple "public static void main( String[] args) { } instruction? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-08-22 09:15 -0700
          Re: Why does Eclipse find error in simple "public static void main( String[] args) { } instruction? Roedy Green <see_website@mindprod.com.invalid> - 2011-08-22 10:02 -0700
            Re: Why does Eclipse find error in simple "public static void main( String[] args) { } instruction? markspace <-@.> - 2011-08-22 10:50 -0700
            Re: Why does Eclipse find error in simple "public static void main( String[] args) { } instruction? Arne Vajhøj <arne@vajhoej.dk> - 2011-08-23 19:03 -0400
        Re: Why does Eclipse find error in simple "public static void main( String[] args) { } instruction? markspace <-@.> - 2011-08-22 10:48 -0700
  Re: Locale.getDefault bug in JDK 1.7 Roedy Green <see_website@mindprod.com.invalid> - 2011-08-22 07:34 -0700
  Re: Locale.getDefault bug in JDK 1.7 markspace <-@.> - 2011-08-22 10:51 -0700
    Re: Locale.getDefault bug in JDK 1.7 Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-22 18:18 +0000
    Re: Locale.getDefault bug in JDK 1.7 Lew <lewbloch@gmail.com> - 2011-08-22 11:22 -0700
      Re: Locale.getDefault bug in JDK 1.7 Lew <lewbloch@gmail.com> - 2011-08-22 12:40 -0700
      Re: Locale.getDefault bug in JDK 1.7 Roedy Green <see_website@mindprod.com.invalid> - 2011-08-23 09:04 -0700
        Re: Locale.getDefault bug in JDK 1.7 Roedy Green <see_website@mindprod.com.invalid> - 2011-08-23 09:10 -0700
    Re: Locale.getDefault bug in JDK 1.7 Roedy Green <see_website@mindprod.com.invalid> - 2011-08-23 08:08 -0700
      Re: Locale.getDefault bug in JDK 1.7 Silvio <silvio@moc.com> - 2011-08-23 17:22 +0200
        Re: Locale.getDefault bug in JDK 1.7 Lew <lewbloch@gmail.com> - 2011-08-23 09:02 -0700
          Re: Locale.getDefault bug in JDK 1.7 Silvio <silvio@moc.com> - 2011-08-23 22:57 +0200
            Re: Locale.getDefault bug in JDK 1.7 Lew <lewbloch@gmail.com> - 2011-08-23 18:03 -0700
              Re: Locale.getDefault bug in JDK 1.7 Silvio <silvio@moc.com> - 2011-08-24 09:09 +0200
                Re: Locale.getDefault bug in JDK 1.7 Roedy Green <see_website@mindprod.com.invalid> - 2011-08-25 07:00 -0700
                Re: Locale.getDefault bug in JDK 1.7 Lew <lewbloch@gmail.com> - 2011-08-25 09:56 -0700
                Re: Locale.getDefault bug in JDK 1.7 supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-08-25 15:50 -0400
                Re: Locale.getDefault bug in JDK 1.7 Roedy Green <see_website@mindprod.com.invalid> - 2011-08-25 12:55 -0700
                Re: Locale.getDefault bug in JDK 1.7 Silvio <silvio@moc.com> - 2011-08-27 00:48 +0200
        Re: Locale.getDefault bug in JDK 1.7 Roedy Green <see_website@mindprod.com.invalid> - 2011-08-25 06:54 -0700
  Re: Locale.getDefault bug in JDK 1.7 Roedy Green <see_website@mindprod.com.invalid> - 2011-08-23 09:43 -0700
    Re: Locale.getDefault bug in JDK 1.7 Roedy Green <see_website@mindprod.com.invalid> - 2011-09-02 08:24 -0700
      Re: Locale.getDefault bug in JDK 1.7 Jeff Higgins <jeff@invalid.invalid> - 2011-09-02 11:34 -0400

csiph-web