Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Locale.getDefault bug in JDK 1.7

Reply
Thread Tools

Locale.getDefault bug in JDK 1.7

 
 
Roedy Green
Guest
Posts: n/a
 
      08-22-2011
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)
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      08-22-2011
On 21 Aug 2011 17:41:53 GMT, http://www.velocityreviews.com/forums/(E-Mail Removed) (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)
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      08-22-2011
On Sun, 21 Aug 2011 23:56:01 -0700, Roedy Green
<(E-Mail Removed)> 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)
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      08-22-2011
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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-22-2011
On Mon, 22 Aug 2011 09:15:29 -0700, Peter Duniho
<(E-Mail Removed)> 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)
 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      08-22-2011
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.

 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      08-22-2011
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.
 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      08-22-2011
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?


 
Reply With Quote
 
Andreas Leitgeb
Guest
Posts: n/a
 
      08-22-2011
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...
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      08-22-2011
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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JDK 1.5 or JDK 1.6 Pep Java 19 07-15-2007 12:06 AM
regarding JDk 141 and JDK 122 for linux 64 bit Platform Jaggu Java 3 01-08-2007 10:47 AM
What is the difference between J2EE, JDK, JDK-SDK, JRE and J2SE packages ? Ulf Meinhardt Java 0 08-10-2006 07:12 PM
jEdit: compiles JDK 1.5.0 ok, but runs JDK 1.4.1 (why?) Thomas G. Marshall Java 5 08-06-2004 04:12 AM
Help with converting IDS from JDK 1.1 to JDK 1.4 Babar Java 1 05-20-2004 09:11 PM



Advertisments