src/share/classes/sun/util/resources/OpenListResourceBundle.java

Print this page
rev 5696 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o packaging changes. by Naoto Sato and Masayoshi Okutsu)

@@ -40,10 +40,11 @@
 
 package sun.util.resources;
 
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.ResourceBundle;
 import java.util.Set;
 import sun.util.ResourceBundleEnumeration;
 

@@ -91,10 +92,28 @@
         loadLookupTablesIfNecessary();
 
         return lookup.keySet();
     }
 
+    @Override
+    public Set<String> keySet() {
+        if (keyset != null) {
+            return keyset;
+        }
+        Set<String> ks = new HashSet<>();
+        ks.addAll(handleGetKeys());
+        if (parent != null) {
+            ks.addAll(parent.keySet());
+        }
+        synchronized (this) {
+            if (keyset == null) {
+                keyset = ks;
+            }
+        }
+        return keyset;
+    }
+
     /**
      * Returns the parent bundle
      */
     public OpenListResourceBundle getParent() {
         return (OpenListResourceBundle)parent;

@@ -116,15 +135,11 @@
 
     /**
      * We lazily load the lookup hashtable.  This function does the
      * loading.
      */
-    private synchronized void loadLookup() {
-        if (lookup != null) {
-            return;
-        }
-
+    private void loadLookup() {
         Object[][] contents = getContents();
         Map<String, Object> temp = createMap(contents.length);
         for (int i = 0; i < contents.length; ++i) {
             // key must be non-null String, value must be non-null
             String key = (String) contents[i][0];

@@ -132,18 +147,23 @@
             if (key == null || value == null) {
                 throw new NullPointerException();
             }
             temp.put(key, value);
         }
+        synchronized (this) {
+            if (lookup == null) {
         lookup = temp;
     }
+        }
+    }
 
     /**
      * Lets subclasses provide specialized Map implementations.
      * Default uses HashMap.
      */
     protected Map<String, Object> createMap(int size) {
         return new HashMap<>(size);
     }
 
-    private Map<String, Object> lookup = null;
+    private volatile Map<String, Object> lookup = null;
+    private volatile Set<String> keyset;
 }