This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ResourceBundle patch


Hi,

The following fixes the bug I was seeing when the default Locale was
change because it might still contain entries that belonged to the old
default Locale. The patch just resets the complete cache when it detects
that the default Locale has changed. (Note that this patch has nothing
todo with the child variants discussion on the mauve-discuss list.)

2002-12-08  Mark Wielaard  <mark@klomp.org>

        * java/util/ResourceBundle.java (resourceBundleCache): Not final.
        (lastDefaultLocale): New field.
        (getBundle): When Locale.getDefault != lastDefaultLocale reset
        resourceBundleCache.

OK to commit?

Cheers,

Mark
Index: java/util/ResourceBundle.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/ResourceBundle.java,v
retrieving revision 1.21
diff -u -r1.21 ResourceBundle.java
--- java/util/ResourceBundle.java	5 Dec 2002 00:49:30 -0000	1.21
+++ java/util/ResourceBundle.java	8 Dec 2002 22:25:54 -0000
@@ -111,7 +111,13 @@
    * second hash map is the localized name, the value is a soft
    * references to the resource bundle.
    */
-  private static final Map resourceBundleCache = new HashMap();
+  private static Map resourceBundleCache;
+
+  /**
+   * The last default Locale we saw. If this ever changes then we have to
+   * reset our caches.
+   */
+  private static Locale lastDefaultLocale;
 
   /**
    * The `empty' locale is created once in order to optimize
@@ -312,6 +318,12 @@
   {
     // This implementation searches the bundle in the reverse direction
     // and builds the parent chain on the fly.
+    Locale defaultLocale = Locale.getDefault();
+    if (defaultLocale != lastDefaultLocale)
+      {
+	resourceBundleCache = new HashMap();
+	lastDefaultLocale = defaultLocale;
+      }
     HashMap cache = (HashMap) resourceBundleCache.get(classLoader);
     StringBuffer sb = new StringBuffer(60);
     sb.append(baseName).append('_').append(locale);
@@ -359,9 +371,9 @@
     // bundle.
     ResourceBundle bundle = tryLocalBundle(baseName, locale,
                                            classLoader, baseBundle, cache);
-    if (bundle == baseBundle && !locale.equals(Locale.getDefault()))
+    if (bundle == baseBundle && !locale.equals(defaultLocale))
       {
-	bundle = tryLocalBundle(baseName, Locale.getDefault(),
+	bundle = tryLocalBundle(baseName, defaultLocale,
 				classLoader, baseBundle, cache);
 	// We need to record that the argument locale maps to the
 	// bundle we just found.  If we didn't find a bundle, record

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]