Index: openide/loaders/src/org/openide/loaders/InstanceDataObject.java =================================================================== RCS file: /cvs/openide/loaders/src/org/openide/loaders/InstanceDataObject.java,v retrieving revision 1.8 diff -c -r1.8 InstanceDataObject.java *** openide/loaders/src/org/openide/loaders/InstanceDataObject.java 21 Nov 2003 14:44:50 -0000 1.8 --- openide/loaders/src/org/openide/loaders/InstanceDataObject.java 5 Feb 2004 17:34:10 -0000 *************** *** 29,34 **** --- 29,35 ---- import org.openide.util.actions.*; import org.openide.nodes.*; import java.util.List; + import java.util.Locale; /** A data object whose only purpose is to supply InstanceCookie. * The instances are created by default instantiation; the name of the class *************** *** 68,73 **** --- 69,76 ---- /** data object name cached in the attribute to prevent instance creation when its InstanceNode is displayed. */ static final String EA_NAME = "name"; // NOI18N + /** Locale of the cached data object name */ + static final String EA_NAMELOCALE = "namelocale"; /** if an instance is modified, what is the delay before it is saved? */ private static final int SAVE_DELAY = 2000; *************** *** 159,165 **** /** get data object name from specified file object */ private static String getName(FileObject fo) { String superName = (String) fo.getAttribute(EA_NAME); ! if (superName != null) return superName; superName = fo.getName(); int bracket = superName.indexOf (OPEN); --- 162,176 ---- /** get data object name from specified file object */ private static String getName(FileObject fo) { String superName = (String) fo.getAttribute(EA_NAME); ! String superLocale = (String) fo.getAttribute(EA_NAMELOCALE); ! ! //issue 34914, InstanceDataObject can cache stale localized display ! //names across a locale change ! if (superName != null && superLocale != null) { ! if (Locale.getDefault().toString().equals(superLocale)) { ! return superName; ! } ! } superName = fo.getName(); int bracket = superName.indexOf (OPEN); *************** *** 669,676 **** /* Overriden to return only first part till the bracket */ public String getName () { ! String superName = (String) getPrimaryFile().getAttribute(EA_NAME); ! if (superName != null) return superName; superName = super.getName(); int bracket = superName.indexOf (OPEN); --- 680,696 ---- /* Overriden to return only first part till the bracket */ public String getName () { ! FileObject fo = getPrimaryFile(); ! String superName = (String) fo.getAttribute(EA_NAME); ! String superLocale = (String) fo.getAttribute(EA_NAMELOCALE); ! ! //issue 34914, InstanceDataObject can cache stale localized display ! //names across a locale change ! if (superName != null && superLocale != null) { ! if (Locale.getDefault().toString().equals(superLocale)) { ! return superName; ! } ! } superName = super.getName(); int bracket = superName.indexOf (OPEN); *************** *** 700,705 **** --- 720,726 ---- protected FileObject handleRename (String name) throws IOException { FileObject fo = getPrimaryFile(); fo.setAttribute(EA_NAME, name); + fo.setAttribute(EA_NAMELOCALE, Locale.getDefault().toString()); return fo; } *************** *** 962,968 **** InstanceDataObject newFile = storeSettings(df, filename, obj, null); if (name != null && !isServiceType) { ! newFile.getPrimaryFile().setAttribute(EA_NAME, name); } return newFile; } --- 983,991 ---- InstanceDataObject newFile = storeSettings(df, filename, obj, null); if (name != null && !isServiceType) { ! FileObject fo = newFile.getPrimaryFile(); ! fo.setAttribute(EA_NAME, name); ! fo.setAttribute(EA_NAMELOCALE, Locale.getDefault().toString()); } return newFile; } Index: core/src/org/netbeans/core/projects/SerialDataConvertor.java =================================================================== RCS file: /cvs/core/src/org/netbeans/core/projects/SerialDataConvertor.java,v retrieving revision 1.25 diff -c -r1.25 SerialDataConvertor.java *** core/src/org/netbeans/core/projects/SerialDataConvertor.java 12 Aug 2003 09:38:26 -0000 1.25 --- core/src/org/netbeans/core/projects/SerialDataConvertor.java 5 Feb 2004 17:34:10 -0000 *************** *** 29,34 **** --- 29,35 ---- import org.openide.loaders.DataObject; import org.openide.loaders.Environment; import org.openide.modules.ModuleInfo; + import org.openide.options.SystemOption; import org.openide.util.Lookup; import org.openide.util.lookup.InstanceContent; import org.openide.util.lookup.AbstractLookup; *************** *** 47,52 **** --- 48,57 ---- * @see org.openide.loaders.InstanceDataObject#EA_NAME */ static final String EA_NAME = "name"; // NOI18N + /** Issue 39414 - we need to track locale to make sure if the locale + * has changed, we don't use a display name from a previous locale */ + static final String EA_NAMELOCALE = "namelocale"; //NOI18N + /** lock used to sync read/write operations for .settings file */ final Object READWRITE_LOCK = new Object(); private final InstanceContent lkpContent; *************** *** 703,731 **** if (!isChanged) firePropertyChange(PROP_SAVE); } ! /** try to synchronize file name with instance name */ private void synchronizeName(Object inst) { ! java.lang.reflect.Method getter; ! try { try { ! getter = inst.getClass().getMethod("getDisplayName", null); // NOI18N ! } catch (NoSuchMethodException me) { ! getter = inst.getClass().getMethod("getName", null); // NOI18N } - } catch (Exception ex) { // do nothing - return; } ! if (!getter.isAccessible()) return; ! try { ! String name = (String) getter.invoke(inst, null); ! String oldName = (String) dobj.getPrimaryFile().getAttribute(EA_NAME); if (name != null && !name.equals(oldName)) { dobj.rename(name); } } catch (Exception ex) { err.annotate(ex, dobj.getPrimaryFile().toString()); ! inform(ex); } } --- 708,743 ---- if (!isChanged) firePropertyChange(PROP_SAVE); } ! /** try to synchronize file name with instance name */ private void synchronizeName(Object inst) { ! java.lang.reflect.Method getter = null; ! String name = null; ! if (inst instanceof SystemOption) { ! name = ((SystemOption) inst).displayName(); ! } else { try { ! try { ! getter = inst.getClass().getMethod("getDisplayName", null); // NOI18N ! } catch (NoSuchMethodException me) { ! getter = inst.getClass().getMethod("getName", null); // NOI18N ! } ! } catch (Exception ex) { // do nothing ! return; } } ! try { ! if (getter != null) { ! name = (String) getter.invoke(inst, null); ! } ! FileObject fo = dobj.getPrimaryFile(); ! String oldName = (String) fo.getAttribute(EA_NAME); if (name != null && !name.equals(oldName)) { dobj.rename(name); } } catch (Exception ex) { err.annotate(ex, dobj.getPrimaryFile().toString()); ! inform(ex); } } Index: core/src/org/netbeans/core/projects/SerialDataNode.java =================================================================== RCS file: /cvs/core/src/org/netbeans/core/projects/SerialDataNode.java,v retrieving revision 1.13 diff -c -r1.13 SerialDataNode.java *** core/src/org/netbeans/core/projects/SerialDataNode.java 30 Jan 2004 10:49:14 -0000 1.13 --- core/src/org/netbeans/core/projects/SerialDataNode.java 5 Feb 2004 17:34:10 -0000 *************** *** 28,33 **** --- 28,34 ---- import java.lang.reflect.Method; import java.io.IOException; import java.lang.ref.WeakReference; + import java.util.Locale; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.Action; *************** *** 39,44 **** --- 40,46 ---- import org.openide.util.*; import org.openide.util.actions.*; import org.openide.nodes.*; + import org.openide.options.SystemOption; /** Node to represent a .settings file. * !!! KEEP CODE SYNCHRONOUS WITH org.netbeans.settings.convertors.SerialDataNode !!! *************** *** 245,251 **** return beanInfoIcon; } ! /** Try to get display name of the bean. */ private String getNameForBean() { try { --- 247,253 ---- return beanInfoIcon; } ! /** Try to get display name of the bean. */ private String getNameForBean() { try { *************** *** 256,269 **** "LBL_BrokenSettings"); //NOI18N } Class clazz = ic.instanceClass(); Method nameGetter; - Class[] param = new Class [0]; try { ! nameGetter = clazz.getMethod ("getName", param); // NOI18N if (nameGetter.getReturnType () != String.class) throw new NoSuchMethodException (); } catch (NoSuchMethodException e) { try { ! nameGetter = clazz.getMethod ("getDisplayName", param); // NOI18N if (nameGetter.getReturnType () != String.class) throw new NoSuchMethodException (); } catch (NoSuchMethodException ee) { return null; --- 258,278 ---- "LBL_BrokenSettings"); //NOI18N } Class clazz = ic.instanceClass(); + if (!SystemOption.class.isAssignableFrom(clazz)) { + //Issue 34914 - we do not want to call getName() on a + //SystemOption, it can return a serialized value from a + //different locale if the locale has changed + Object o = ic.instanceCreate(); + setSettingsInstance (o); + return ((SystemOption) o).displayName(); + } Method nameGetter; try { ! nameGetter = clazz.getMethod ("getDisplayName", null); // NOI18N if (nameGetter.getReturnType () != String.class) throw new NoSuchMethodException (); } catch (NoSuchMethodException e) { try { ! nameGetter = clazz.getMethod ("getName", null); // NOI18N if (nameGetter.getReturnType () != String.class) throw new NoSuchMethodException (); } catch (NoSuchMethodException ee) { return null; *************** *** 347,353 **** if (isAfterNodeConstruction == null) return super.getName(); return getDisplayName(); } ! /** Get the display name for the node. * A filesystem may {@link org.openide.filesystems.FileSystem#getStatus specially alter} this. * @return the desired name --- 356,362 ---- if (isAfterNodeConstruction == null) return super.getName(); return getDisplayName(); } ! /** Get the display name for the node. * A filesystem may {@link org.openide.filesystems.FileSystem#getStatus specially alter} this. * @return the desired name *************** *** 355,360 **** --- 364,375 ---- public String getDisplayName () { String name; Object setting = getSettingInstance(); + + if (setting instanceof SystemOption) { + String result = (((SystemOption) setting)).displayName(); + return result; + } + if (setting != null && isNameChanged) { // due to async storing ask a bean for name first name = getNameForBean(); *************** *** 363,370 **** } } ! name = (String) getDataObject().getPrimaryFile(). ! getAttribute(SerialDataConvertor.EA_NAME); if (name == null) { try { String def = "\b"; // NOI18N --- 378,393 ---- } } ! FileObject fo = getDataObject().getPrimaryFile(); ! ! name = (String) fo.getAttribute(SerialDataConvertor.EA_NAME); ! String locale = (String) fo.getAttribute(SerialDataConvertor.EA_NAMELOCALE); ! ! //issue 34914, do not persist cached display names across locale changes ! if (!Locale.getDefault().toString().equals(locale)) { ! name = null; ! } ! if (name == null) { try { String def = "\b"; // NOI18N Index: core/settings/src/org/netbeans/modules/settings/convertors/SerialDataConvertor.java =================================================================== RCS file: /cvs/core/settings/src/org/netbeans/modules/settings/convertors/SerialDataConvertor.java,v retrieving revision 1.24 diff -c -r1.24 SerialDataConvertor.java *** core/settings/src/org/netbeans/modules/settings/convertors/SerialDataConvertor.java 26 Jan 2004 17:19:34 -0000 1.24 --- core/settings/src/org/netbeans/modules/settings/convertors/SerialDataConvertor.java 5 Feb 2004 17:34:11 -0000 *************** *** 37,42 **** --- 37,43 ---- import org.netbeans.spi.settings.Convertor; import org.netbeans.modules.settings.Env; import org.netbeans.modules.settings.ScheduledRequest; + import org.openide.options.SystemOption; /** Convertor handles serialdata format described in * http://www.netbeans.org/dtds/sessionsettings-1_0.dtd. The convertor overrides *************** *** 46,58 **** * * @author Jan Pokorsky */ public final class SerialDataConvertor extends org.openide.filesystems.FileChangeAdapter implements PropertyChangeListener, FileSystem.AtomicAction { /** data object name cached in the attribute to prevent instance creation when * its node is displayed. ! * @see org.openide.loaders.InstanceDataObject#EA_NAME */ static final String EA_NAME = "name"; // NOI18N /** lock used to sync read/write operations for .settings file */ final Object READWRITE_LOCK = new Object(); private final InstanceContent lkpContent; --- 47,68 ---- * * @author Jan Pokorsky */ + + //XXX If the only difference between this and org.netbeans.core.projects.SerialDataConvertor + //is the package name, why not have only one version and copy/change package in the + //build process. This is not at all fun to edit. + public final class SerialDataConvertor extends org.openide.filesystems.FileChangeAdapter implements PropertyChangeListener, FileSystem.AtomicAction { /** data object name cached in the attribute to prevent instance creation when * its node is displayed. ! * @see org.openide.loaders.InstanceDataObject#sE */ static final String EA_NAME = "name"; // NOI18N + /** Issue 39414 - we need to track locale to make sure if the locale + * has changed, we don't use a display name from a previous locale */ + static final String EA_NAMELOCALE = "namelocale"; //NOI18N + /** lock used to sync read/write operations for .settings file */ final Object READWRITE_LOCK = new Object(); private final InstanceContent lkpContent; *************** *** 776,804 **** /** try to synchronize file name with instance name */ private void synchronizeName(Object inst) { ! java.lang.reflect.Method getter; ! try { try { ! getter = inst.getClass().getMethod("getDisplayName", null); // NOI18N ! } catch (NoSuchMethodException me) { ! getter = inst.getClass().getMethod("getName", null); // NOI18N } - } catch (Exception ex) { // do nothing - return; } ! try { ! String name = (String) getter.invoke(inst, null); ! String oldName = (String) dobj.getPrimaryFile().getAttribute(EA_NAME); if (name != null && !name.equals(oldName)) { dobj.rename(name); } } catch (Exception ex) { err.annotate(ex, dobj.getPrimaryFile().toString()); ! inform(ex); } } - } //////////////////////////////////////////////////////////////////////////// --- 786,821 ---- /** try to synchronize file name with instance name */ private void synchronizeName(Object inst) { ! java.lang.reflect.Method getter = null; ! String name = null; ! if (inst instanceof SystemOption) { ! name = ((SystemOption) inst).displayName(); ! } else { try { ! try { ! getter = inst.getClass().getMethod("getDisplayName", null); // NOI18N ! } catch (NoSuchMethodException me) { ! getter = inst.getClass().getMethod("getName", null); // NOI18N ! } ! } catch (Exception ex) { // do nothing ! return; } } ! try { ! if (getter != null) { ! name = (String) getter.invoke(inst, null); ! } ! FileObject fo = dobj.getPrimaryFile(); ! String oldName = (String) fo.getAttribute(EA_NAME); if (name != null && !name.equals(oldName)) { dobj.rename(name); } } catch (Exception ex) { err.annotate(ex, dobj.getPrimaryFile().toString()); ! inform(ex); } } } //////////////////////////////////////////////////////////////////////////// Index: core/settings/src/org/netbeans/modules/settings/convertors/SerialDataNode.java =================================================================== RCS file: /cvs/core/settings/src/org/netbeans/modules/settings/convertors/SerialDataNode.java,v retrieving revision 1.11 diff -c -r1.11 SerialDataNode.java *** core/settings/src/org/netbeans/modules/settings/convertors/SerialDataNode.java 30 Jan 2004 10:49:13 -0000 1.11 --- core/settings/src/org/netbeans/modules/settings/convertors/SerialDataNode.java 5 Feb 2004 17:34:11 -0000 *************** *** 28,33 **** --- 28,34 ---- import java.lang.reflect.Method; import java.io.IOException; import java.lang.ref.WeakReference; + import java.util.Locale; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.Action; *************** *** 39,44 **** --- 40,46 ---- import org.openide.util.*; import org.openide.util.actions.*; import org.openide.nodes.*; + import org.openide.options.SystemOption; /** Node to represent a .settings file. * !!! KEEP CODE SYNCHRONOUS WITH org.netbeans.core.projects.SerialDataNode !!! *************** *** 54,60 **** private boolean noBeanInfo = false; private final SerialDataConvertor convertor; private WeakReference settingInstance = new WeakReference(null); ! private boolean isNameChanged = false; /** true after passing the constructors code * @see #getName */ --- 56,62 ---- private boolean noBeanInfo = false; private final SerialDataConvertor convertor; private WeakReference settingInstance = new WeakReference(null); ! private boolean isNameChanged = true; /** true after passing the constructors code * @see #getName */ *************** *** 265,278 **** "LBL_BrokenSettings"); //NOI18N } Class clazz = ic.instanceClass(); Method nameGetter; - Class[] param = new Class [0]; try { ! nameGetter = clazz.getMethod ("getName", param); // NOI18N if (nameGetter.getReturnType () != String.class) throw new NoSuchMethodException (); } catch (NoSuchMethodException e) { try { ! nameGetter = clazz.getMethod ("getDisplayName", param); // NOI18N if (nameGetter.getReturnType () != String.class) throw new NoSuchMethodException (); } catch (NoSuchMethodException ee) { return null; --- 267,287 ---- "LBL_BrokenSettings"); //NOI18N } Class clazz = ic.instanceClass(); + if (!SystemOption.class.isAssignableFrom(clazz)) { + //Issue 34914 - we do not want to call getName() on a + //SystemOption, it can return a serialized value from a + //different locale if the locale has changed + Object o = ic.instanceCreate(); + setSettingsInstance (o); + return ((SystemOption) o).displayName(); + } Method nameGetter; try { ! nameGetter = clazz.getMethod ("getDisplayName", null); // NOI18N if (nameGetter.getReturnType () != String.class) throw new NoSuchMethodException (); } catch (NoSuchMethodException e) { try { ! nameGetter = clazz.getMethod ("getName", null); // NOI18N if (nameGetter.getReturnType () != String.class) throw new NoSuchMethodException (); } catch (NoSuchMethodException ee) { return null; *************** *** 356,362 **** if (isAfterNodeConstruction == null) return super.getName(); return getDisplayName(); } ! /** Get the display name for the node. * A filesystem may {@link org.openide.filesystems.FileSystem#getStatus specially alter} this. * @return the desired name --- 365,371 ---- if (isAfterNodeConstruction == null) return super.getName(); return getDisplayName(); } ! /** Get the display name for the node. * A filesystem may {@link org.openide.filesystems.FileSystem#getStatus specially alter} this. * @return the desired name *************** *** 364,369 **** --- 373,384 ---- public String getDisplayName () { String name; Object setting = getSettingInstance(); + + if (setting instanceof SystemOption) { + String result = (((SystemOption) setting)).displayName(); + return result; + } + if (setting != null && isNameChanged) { // due to async storing ask a bean for name first name = getNameForBean(); *************** *** 372,379 **** } } ! name = (String) getDataObject().getPrimaryFile(). ! getAttribute(SerialDataConvertor.EA_NAME); if (name == null) { try { String def = "\b"; // NOI18N --- 387,402 ---- } } ! FileObject fo = getDataObject().getPrimaryFile(); ! ! name = (String) fo.getAttribute(SerialDataConvertor.EA_NAME); ! String locale = (String) fo.getAttribute(SerialDataConvertor.EA_NAMELOCALE); ! ! //issue 34914, do not persist cached display names across locale changes ! if (!Locale.getDefault().toString().equals(locale)) { ! name = null; ! } ! if (name == null) { try { String def = "\b"; // NOI18N