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


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

Locale.getDefault bug in JDK 1.7

From Roedy Green <see_website@mindprod.com.invalid>
Newsgroups comp.lang.java.programmer
Subject Locale.getDefault bug in JDK 1.7
Date 2011-08-21 23:56 -0700
Organization Canadian Mind Products
Message-ID <k4u357dqe5lejh08eiadvd2ad2kji1ivho@4ax.com> (permalink)

Show all headers | View raw


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) 

Back to comp.lang.java.programmer | Previous | NextNext 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