]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Fix NPE when dictDir was not a dir.
authorThad Hughes <thad.hughes@gmail.com>
Wed, 8 Feb 2012 23:44:40 +0000 (15:44 -0800)
committerThad Hughes <thad.hughes@gmail.com>
Wed, 8 Feb 2012 23:44:40 +0000 (15:44 -0800)
src/com/hughes/android/dictionary/DictionaryApplication.java
src/com/hughes/android/dictionary/DictionaryManagerActivity.java

index d36e99d718cdbfe77f7438b622668b6d89384132..25a5f445a6168452ca92e8968cb0656c0af43a1e 100644 (file)
@@ -256,27 +256,31 @@ public class DictionaryApplication extends Application {
         // Pick them up and put them at the end of the list.
         final List<String> toAddSorted = new ArrayList<String>();
         final File[] dictDirFiles = getDictDir().listFiles();
-        for (final File file : dictDirFiles) {
-          if (file.getName().endsWith(".zip")) {
-            if (DOWNLOADABLE_NAME_TO_INFO.containsKey(file.getName().replace(".zip", ""))) {
-              file.delete();
+        if (dictDirFiles != null) {
+          for (final File file : dictDirFiles) {
+            if (file.getName().endsWith(".zip")) {
+              if (DOWNLOADABLE_NAME_TO_INFO.containsKey(file.getName().replace(".zip", ""))) {
+                file.delete();
+              }
             }
+            if (!file.getName().endsWith(".quickdic")) {
+              continue;
+            }
+            if (newDictionaryConfig.dictionaryInfoCache.containsKey(file.getName())) {
+              // We have it in our list already.
+              continue;
+            }
+            final DictionaryInfo dictionaryInfo = Dictionary.getDictionaryInfo(file);
+            if (dictionaryInfo == null) {
+              Log.e(LOG, "Unable to parse dictionary: " + file.getPath());
+              continue;
+            }
+            
+            toAddSorted.add(file.getName());
+            newDictionaryConfig.dictionaryInfoCache.put(file.getName(), dictionaryInfo);
           }
-          if (!file.getName().endsWith(".quickdic")) {
-            continue;
-          }
-          if (newDictionaryConfig.dictionaryInfoCache.containsKey(file.getName())) {
-            // We have it in our list already.
-            continue;
-          }
-          final DictionaryInfo dictionaryInfo = Dictionary.getDictionaryInfo(file);
-          if (dictionaryInfo == null) {
-            Log.e(LOG, "Unable to parse dictionary: " + file.getPath());
-            continue;
-          }
-          
-          toAddSorted.add(file.getName());
-          newDictionaryConfig.dictionaryInfoCache.put(file.getName(), dictionaryInfo);
+        } else {
+          Log.w(LOG, "dictDir is not a diretory: " + getDictDir().getPath());
         }
         if (!toAddSorted.isEmpty()) {
           Collections.sort(toAddSorted, uncompressedFilenameComparator);
index f7db7de6cd886223fd0d2e81e619445fea89dcd1..ba56163f9aa01f20e0cd7191e795eaf131425a22 100644 (file)
@@ -45,7 +45,6 @@ import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
-import com.hughes.android.dictionary.C.Theme;
 import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;
 import com.hughes.android.util.IntentLauncher;
 import com.hughes.util.StringUtil;