-
Bug
-
Resolution: Fixed
-
P3
-
6
-
b14
-
x86
-
linux
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2147681 | 6u2 | Naoto Sato | P3 | Resolved | Fixed | b01 |
FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Server VM (build 1.6.0-b105, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux dgtp60 2.6.18.2-34-default #1 SMP Mon Nov 27 11:46:27 UTC 2006 i686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
In Java 5, an action-properties could be split to an locale-specific file (e.g. actions_de_DE.properties) and a default file (e.g. actions.properties) to specify menu actions etc. That worked quite well - german menus with german default-locale and english menus with english default-locale.
Now the same code with the given example file names leads to english menu entries with german default locale.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create two action-property files:
actions.properties
actions_de_DE.properties
Create an action using reflection from the property files.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
LANG=de_DE@euro
DefaultLocale=de_DE - Command[Name=Neuer
Fehler|ShortDescription=Erstellt einen neuen Fehler]
LANG=c
DefaultLocale=en_US - Command[Name=New Bug|ShortDescription=Create a new
bug]
ACTUAL -
> LANG=de_DE@euro
> java -jar BugInternational.jar
DefaultLocale=de_DE - Command[Name=New Bug|ShortDescription=Create a new
bug]
> LANG=c
> java -jar BugInternational.jar
DefaultLocale=en_US - Command[Name=New Bug|ShortDescription=Create a new
bug]
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/**
* @author David Gunkel
* Show Internationalization-Bug
*
*/
import java.awt.event.ActionEvent;
import java.lang.reflect.Method;
import java.util.Locale;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.UIDefaults;
public class Command extends AbstractAction {
private static final long serialVersionUID = 1L;
private final static String actionKeys[] = { Action.NAME, Action.SHORT_DESCRIPTION };
private final String methodName;
private final Object target;
public Command(String methodName, UIDefaults defaults) {
// assert methodName != null or empty, defaults != null
super(methodName);
this.methodName = methodName;
this.target = this;
for (String k : actionKeys) {
String mk = methodName + "." + k;
putValue(k, defaults.get(mk));
}
}
private Method retrieveMethod() {
Method m = null;
Class c = target.getClass();
try {
m = c.getMethod(methodName);
}
catch (NoSuchMethodException ign) {
try {
m = c.getMethod(methodName, ActionEvent.class);
}
catch (Exception e) {
System.err.println(e);
e.printStackTrace();
System.exit(-1);
}
}
return m;
}
public void newBug() {
System.out.println(this.toString());
}
protected void actionFailed(ActionEvent actionEvent, Exception e) {
System.err.println(actionEvent);
e.printStackTrace();
}
public void actionPerformed(ActionEvent actionEvent) {
if ((target == null) || (methodName == null)) {
return;
}
Method m = this.retrieveMethod();
try {
if (m.getGenericParameterTypes().length == 0) {
m.invoke(target);
}
else {
m.invoke(target, actionEvent);
}
}
catch (Exception e) {
actionFailed(actionEvent, e);
}
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("DefaultLocale=" + Locale.getDefault() + " - ");
sb.append(getClass().getName());
sb.append("[");
String delim = "";
for (String k : actionKeys) {
sb.append(delim).append(k).append("=").append(getValue(k));
delim = "|";
}
sb.append("]");
return sb.toString();
}
public static void main(String[] args) {
UIDefaults defaults = new UIDefaults();
defaults.addResourceBundle("actions");
Action a = new Command("newBug", defaults);
a.actionPerformed(null);
}
}
And here the property-files.
actions_de_DE.properties:
newBug.Name=Neuer Fehler
newBug.ShortDescription=Erstellt einen neuen Fehler
actions.properties:
newBug.Name=New Bug
newBug.ShortDescription=Create a new bug
---------- END SOURCE ----------
Release Regression From : 5
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Server VM (build 1.6.0-b105, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux dgtp60 2.6.18.2-34-default #1 SMP Mon Nov 27 11:46:27 UTC 2006 i686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
In Java 5, an action-properties could be split to an locale-specific file (e.g. actions_de_DE.properties) and a default file (e.g. actions.properties) to specify menu actions etc. That worked quite well - german menus with german default-locale and english menus with english default-locale.
Now the same code with the given example file names leads to english menu entries with german default locale.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create two action-property files:
actions.properties
actions_de_DE.properties
Create an action using reflection from the property files.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
LANG=de_DE@euro
DefaultLocale=de_DE - Command[Name=Neuer
Fehler|ShortDescription=Erstellt einen neuen Fehler]
LANG=c
DefaultLocale=en_US - Command[Name=New Bug|ShortDescription=Create a new
bug]
ACTUAL -
> LANG=de_DE@euro
> java -jar BugInternational.jar
DefaultLocale=de_DE - Command[Name=New Bug|ShortDescription=Create a new
bug]
> LANG=c
> java -jar BugInternational.jar
DefaultLocale=en_US - Command[Name=New Bug|ShortDescription=Create a new
bug]
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/**
* @author David Gunkel
* Show Internationalization-Bug
*
*/
import java.awt.event.ActionEvent;
import java.lang.reflect.Method;
import java.util.Locale;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.UIDefaults;
public class Command extends AbstractAction {
private static final long serialVersionUID = 1L;
private final static String actionKeys[] = { Action.NAME, Action.SHORT_DESCRIPTION };
private final String methodName;
private final Object target;
public Command(String methodName, UIDefaults defaults) {
// assert methodName != null or empty, defaults != null
super(methodName);
this.methodName = methodName;
this.target = this;
for (String k : actionKeys) {
String mk = methodName + "." + k;
putValue(k, defaults.get(mk));
}
}
private Method retrieveMethod() {
Method m = null;
Class c = target.getClass();
try {
m = c.getMethod(methodName);
}
catch (NoSuchMethodException ign) {
try {
m = c.getMethod(methodName, ActionEvent.class);
}
catch (Exception e) {
System.err.println(e);
e.printStackTrace();
System.exit(-1);
}
}
return m;
}
public void newBug() {
System.out.println(this.toString());
}
protected void actionFailed(ActionEvent actionEvent, Exception e) {
System.err.println(actionEvent);
e.printStackTrace();
}
public void actionPerformed(ActionEvent actionEvent) {
if ((target == null) || (methodName == null)) {
return;
}
Method m = this.retrieveMethod();
try {
if (m.getGenericParameterTypes().length == 0) {
m.invoke(target);
}
else {
m.invoke(target, actionEvent);
}
}
catch (Exception e) {
actionFailed(actionEvent, e);
}
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("DefaultLocale=" + Locale.getDefault() + " - ");
sb.append(getClass().getName());
sb.append("[");
String delim = "";
for (String k : actionKeys) {
sb.append(delim).append(k).append("=").append(getValue(k));
delim = "|";
}
sb.append("]");
return sb.toString();
}
public static void main(String[] args) {
UIDefaults defaults = new UIDefaults();
defaults.addResourceBundle("actions");
Action a = new Command("newBug", defaults);
a.actionPerformed(null);
}
}
And here the property-files.
actions_de_DE.properties:
newBug.Name=Neuer Fehler
newBug.ShortDescription=Erstellt einen neuen Fehler
actions.properties:
newBug.Name=New Bug
newBug.ShortDescription=Create a new bug
---------- END SOURCE ----------
Release Regression From : 5
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
- backported by
-
JDK-2147681 Menu-internationalization differs from Java 5.0
- Resolved
- relates to
-
JDK-6280517 Performance: Using ResourceBundle.Control API to speed up the resource bundle search
- Resolved