Locale.getDefault bug in JDK 1.7
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)