]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/localisation/Language.java
Fix: Always synchronize Language access.
[gigi.git] / src / org / cacert / gigi / localisation / Language.java
index 5e11f09c58b13049bf156628fda1ac2f7cc6ad73..95971120f39df4151e997ff2af1d4694cd1bfcee 100644 (file)
@@ -27,12 +27,15 @@ public class Language {
     static {
         LinkedList<Locale> supported = new LinkedList<>();
         File locales = new File("locale");
-        for (File f : locales.listFiles()) {
-            if ( !f.getName().endsWith(".xml")) {
-                continue;
+        File[] listFiles = locales.listFiles();
+        if (listFiles != null) {
+            for (File f : listFiles) {
+                if ( !f.getName().endsWith(".xml")) {
+                    continue;
+                }
+                String language = f.getName().split("\\.", 2)[0];
+                supported.add(getLocaleFromString(language));
             }
-            String language = f.getName().split("\\.", 2)[0];
-            supported.add(getLocaleFromString(language));
         }
         Collections.sort(supported, new Comparator<Locale>() {
 
@@ -109,8 +112,11 @@ public class Language {
         if ( !file.exists()) {
             return null;
         }
-        Language lang = langs.get(locale.toString());
-        if (lang == null) {
+        synchronized (Language.class) {
+            Language lang = langs.get(locale.toString());
+            if (lang != null) {
+                return lang;
+            }
             try {
                 lang = new Language(locale);
                 langs.put(locale.toString(), lang);
@@ -121,8 +127,8 @@ public class Language {
             } catch (SAXException e) {
                 e.printStackTrace();
             }
+            return lang;
         }
-        return lang;
     }
 
     public Locale getLocale() {