JDK-6530694 : Menu-internationalization differs from Java 5.0
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2007-03-02
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u2Fixed 7 b14Fixed
Related Reports
Relates :  
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/
14-03-2007

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.
06-03-2007