Locale.getDefault bug in JDK 1.7

R

Roedy Green

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)
 
R

Roedy Green

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)
 
R

Roedy Green

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)
 
L

Lew

Patricia said:
Roedy said:
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.
 
R

Roedy Green

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)
 
M

markspace

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.
 
M

markspace

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.
 
M

markspace

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?
 
A

Andreas Leitgeb

markspace said:
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...
 
L

Lew

[context restoration]
....

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.
 
L

Lew

<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>
 
R

Roedy Green

It is not returning USA even though my OS


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

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)
 
S

Silvio

Blast. That is a DSK typo I meant to write

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?
 
R

Roedy Green

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)
 
R

Roedy Green

/*
* [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)
 
R

Roedy Green

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)
 
L

Lew

Silvio said:

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top