United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6530694 Menu-internationalization differs from Java 5.0
6530694 : Menu-internationalization differs from Java 5.0

Details
Type:
Bug
Submit Date:
2007-03-02
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
core-libs
OS:
linux
Sub-Component:
java.util:i18n
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:
7

Related Reports
Backport:
Relates:

Sub Tasks

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

                                    

Comments
SUGGESTED FIX

http://javaweb.sfbay/jcg/7/i18n/6530694/
                                     
2007-03-14
EVALUATION

It looks like this is a regression caused by the fix for 6280517.  The swing portion of the fix seems to assume that the getBundle() call in the UIDefaults class is only for loading JDK provided Swing resoure bundles.  But this is actually used for application defined resource bundles as well.  In this problem case, CoreResourceBundleControl does not include de_DE in its candidate locales, it falls back to the root bundle.

It can easily be fixed by just reverting the fix for 6280517, but it also causes cold startup performance regression.
                                     
2007-03-06



Hardware and Software, Engineered to Work Together