I have just installed jre7 and I\'m surprised to see that my default locale is now en_US. With jre6 it was de_CH.
What is different with jre7? Is the default locale
This really looks like a bug to me:
public static void main(String[] args) throws FileNotFoundException, IOException {
System.err.println(Locale.getDefault());
}
running this with java 5 or java 6 prints: 'nl_NL' java7: 'en_US'
Check the setting "Location" in Windows control panel Regional and language options (German: "Region und Sprache", "Aufenthaltsort").
What about setting your Locale at the start of the program in the following way, depending on java version:
public class LocaleFormatter {
private static Locale locale;
private LocaleFormatter() {
}
public static Locale setDefaultLocale() {
if (locale == null) {
if (!System.getProperty("java.version").startsWith("1.7.")) {
locale = Locale.getDefault();
} else {
try {
Class localeClass = Class.forName("java.util.Locale");
Class categoryClass = Class.forName("java.util.Locale$Category");
Object format = null;
for (Object constant : categoryClass.getEnumConstants()) {
if (constant.toString().equals("FORMAT")) {
format = constant;
}
}
Method method = localeClass.getMethod("getDefault", categoryClass);
locale = (Locale) method.invoke(Locale.getDefault(), format);
Locale.setDefault(locale);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
return locale;
}
}
If you are brave enough you can call the :
Locale.setDefault(Locale.getDefault());
This sets the default Locale for both of those categories
public static synchronized void setDefault(Locale newLocale) {
setDefault(Category.DISPLAY, newLocale);
setDefault(Category.FORMAT, newLocale);
defaultLocale = newLocale;
}
But this of course could cause side effects.
This is as designed. Java 7 has changed the way Locale.getDefault()
works. A defect has been entered with Oracle, but they basically said this is As Designed.
To sum up, you must modify the Display Language of the OS. Modifying the Region Format only is no longer sufficient.
Read the bug report here: Locale.getDefault() returns wrong Locale for Java SE 7
There seems to be some changes regarding Locale in Java 7, namely differentiation between UI and 'user' locale. See this. There is now setDefault(Locale.Category, Locale)
. However, this does not really explain what you are experiencing - I'm merely pointing out the fact that there has been changes in Java 7 regarding locale handling.