]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Fix some code inspection warnings.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Mon, 20 Aug 2018 21:18:08 +0000 (23:18 +0200)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Mon, 20 Aug 2018 21:19:47 +0000 (23:19 +0200)
Util
src/com/hughes/android/dictionary/AboutActivity.java
src/com/hughes/android/dictionary/DictionaryActivity.java
src/com/hughes/android/dictionary/DictionaryApplication.java
src/com/hughes/android/dictionary/DictionaryManagerActivity.java
src/com/hughes/android/dictionary/HtmlDisplayActivity.java
src/com/hughes/android/dictionary/PreferenceActivity.java
src/com/hughes/android/dictionary/engine/HtmlEntry.java
src/com/hughes/android/dictionary/engine/PairEntry.java
src/com/hughes/android/util/PersistentObjectCache.java

diff --git a/Util b/Util
index 47ba24f81320001cf29f46e0069e0e7e83ad3553..272a7b504cb85b8dc2bba3718725b547750434b1 160000 (submodule)
--- a/Util
+++ b/Util
@@ -1 +1 @@
-Subproject commit 47ba24f81320001cf29f46e0069e0e7e83ad3553
+Subproject commit 272a7b504cb85b8dc2bba3718725b547750434b1
index 7af07bd57382fd7506f33cfffa90755c0153db75..2f1ee139b478be23628d1b377b67414ae58f1fe5 100644 (file)
@@ -37,7 +37,7 @@ public final class AboutActivity extends Activity {
                 PackageInfo p = pm.getPackageInfo(getPackageName(), 0);
                 ver = p.versionName + " (ID " + p.versionCode + ")";
             }
-        } catch (Exception e) {
+        } catch (Exception ignored) {
         }
         TextView titleView = findViewById(R.id.titleText);
         titleView.setText("QuickDic " + ver);
index b9b5043d21694261456efaa313080963633747ef..0637f165ff275410e30c3b8f365fced678ee3291 100644 (file)
@@ -1285,7 +1285,7 @@ public class DictionaryActivity extends AppCompatActivity {
             Log.d(LOG, "Trying to hide soft keyboard.");
             final InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
             View focus = getCurrentFocus();
-            if (focus != null) {
+            if (inputManager != null && focus != null) {
                 inputManager.hideSoftInputFromWindow(focus.getWindowToken(),
                                                      InputMethodManager.HIDE_NOT_ALWAYS);
             }
@@ -1501,7 +1501,7 @@ public class DictionaryActivity extends AppCompatActivity {
                 DisplayMetrics dm = new DisplayMetrics();
                 getWindowManager().getDefaultDisplay().getMetrics(dm);
                 scale = dm.density;
-            } catch (NullPointerException e)
+            } catch (NullPointerException ignored)
             {}
             // Convert the dps to pixels, based on density scale
             mPaddingDefault = (int) (PADDING_DEFAULT_DP * scale + 0.5f);
index fac485124967dd0a4a6206b1a5a4da5bee00cc9f..c17c7ef82975e407f707d4da0cf8e67963edb2da 100644 (file)
@@ -157,7 +157,7 @@ public enum DictionaryApplication {
         }
         try {
             reader.close();
-        } catch (IOException e) {}
+        } catch (IOException ignored) {}
     }
 
     public synchronized void init(Context c) {
@@ -256,7 +256,7 @@ public enum DictionaryApplication {
         File efd = null;
         try {
             efd = appContext.getExternalFilesDir(null);
-        } catch (Exception e) {
+        } catch (Exception ignored) {
         }
         if (efd != null) {
             efd.mkdirs();
@@ -295,7 +295,7 @@ public enum DictionaryApplication {
         try {
             testfile.delete();
             res = testfile.createNewFile() & testfile.delete();
-        } catch (Exception e) {
+        } catch (Exception ignored) {
         }
         return res;
     }
index 3cc5e823fee1c5e752c40d933c17634e8c0c51e9..265059ee108e9ff951743fa88b177b8162063269 100644 (file)
@@ -224,7 +224,7 @@ public class DictionaryManagerActivity extends AppCompatActivity {
                 }
             }
             zipFile = new ZipInputStream(new BufferedInputStream(zipFileStream));
-            ZipEntry zipEntry = null;
+            ZipEntry zipEntry;
             while ((zipEntry = zipFile.getNextEntry()) != null) {
                 // Note: this check prevents security issues like accidental path
                 // traversal, which unfortunately ZipInputStream has no protection against.
@@ -258,14 +258,15 @@ public class DictionaryManagerActivity extends AppCompatActivity {
         } finally {
             try {
                 if (zipOut != null) zipOut.close();
-            } catch (IOException e) {}
+            } catch (IOException ignored) {}
             try {
                 if (zipFile != null) zipFile.close();
-            } catch (IOException e) {}
+            } catch (IOException ignored) {}
             try {
                 if (zipFileStream != null) zipFileStream.close();
-            } catch (IOException e) {}
-            if (localZipFile != null && delete) localZipFile.delete();
+            } catch (IOException ignored) {}
+            if (localZipFile != null && delete) //noinspection ResultOfMethodCallIgnored
+                localZipFile.delete();
         }
         return result;
     }
@@ -839,6 +840,14 @@ public class DictionaryManagerActivity extends AppCompatActivity {
 
         DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
 
+        if (downloadManager == null) {
+            String msg = getString(R.string.downloadManagerQueryFailed);
+            new AlertDialog.Builder(DictionaryManagerActivity.this).setTitle(getString(R.string.error))
+                    .setMessage(getString(R.string.downloadFailed, msg))
+                    .setNeutralButton("Close", null).show();
+            return;
+        }
+
         try {
             downloadManager.enqueue(request);
         } catch (SecurityException e) {
index c2f4a8398bc8326b36213d145b27b938ab207fe0..7a8a7e89c4a286561b0753e2ac4a0f302b766318 100644 (file)
@@ -86,7 +86,7 @@ public final class HtmlDisplayActivity extends AppCompatActivity {
             html = StringUtil.readToString(res);
             try {
                 res.close();
-            } catch (IOException e) {
+            } catch (IOException ignored) {
             }
         } else {
             html = getIntent().getStringExtra(HTML);
index 40784af0161a25bf6e9ab9cf854dccce8afb6697..cda9a80cd411593ebde602c7e85ba177faee2b1c 100644 (file)
@@ -103,7 +103,7 @@ public class PreferenceActivity extends android.preference.PreferenceActivity
                 File efd = null;
                 try {
                     efd = getApplicationContext().getExternalFilesDir(null);
-                } catch (Exception e) {
+                } catch (Exception ignored) {
                 }
                 if (efd != null) {
                     String externalFilesDir = efd.getAbsolutePath();
index 1e34b00a70150d187868e4a038d3821b88ebca7c..1a602a017ad8d8a0c59a511a5656efe4fb5ff958 100644 (file)
@@ -1,6 +1,8 @@
 
 package com.hughes.android.dictionary.engine;
 
+import android.support.annotation.NonNull;
+
 import com.hughes.util.StringUtil;
 import com.hughes.util.raf.RAFListSerializer;
 import com.hughes.util.raf.RAFListSerializerSkippable;
@@ -137,7 +139,7 @@ public class HtmlEntry extends AbstractEntry implements Comparable<HtmlEntry> {
     }
 
     @Override
-    public int compareTo(HtmlEntry another) {
+    public int compareTo(@NonNull HtmlEntry another) {
         if (title.compareTo(another.title) != 0) {
             return title.compareTo(another.title);
         }
index a82063efed31c3b55d1a418b9b34dec0cbf56411..2fac99f75201f0d73f73aa7f83ee536b10c95c9a 100644 (file)
@@ -14,6 +14,8 @@
 
 package com.hughes.android.dictionary.engine;
 
+import android.support.annotation.NonNull;
+
 import com.hughes.util.StringUtil;
 import com.hughes.util.raf.RAFListSerializerSkippable;
 import com.hughes.util.raf.RAFSerializable;
@@ -219,7 +221,7 @@ public class PairEntry extends AbstractEntry implements RAFSerializable<PairEntr
     }
 
     @Override
-    public int compareTo(final PairEntry that) {
+    public int compareTo(@NonNull final PairEntry that) {
         return this.getRawText(false).compareTo(that.getRawText(false));
     }
 
index 938142c341591d7551dfa16dc5ebe55be7e859b5..17be956b10563cc1ebb20ae723434af4e8cf8038 100644 (file)
@@ -86,7 +86,7 @@ public class PersistentObjectCache {
                 Log.e(getClass().getSimpleName(), "Deserialization failed: " + src, e);
                 try {
                     if (in != null) in.close();
-                } catch (IOException e2) {}
+                } catch (IOException ignored) {}
                 return null;
             }
             objects.put(filename, object);
@@ -108,7 +108,7 @@ public class PersistentObjectCache {
         }
         try {
             if (out != null) out.close();
-        } catch (IOException e) {}
+        } catch (IOException ignored) {}
     }
 
     private PersistentObjectCache(final Context context) {