Browse Source

Merge pull request #2752 from nextcloud/useFinal

findbugs: several warnings
Andy Scherzinger 6 years ago
parent
commit
deaa26a102

+ 4 - 1
findbugs-filter.xml

@@ -5,4 +5,7 @@
     <Match>
         <Class name="~.*\.Manifest\$.*"/>
     </Match>
-</FindBugsFilter>
+    <Match>
+        <Class name="~.*\.R\$.*"/>
+    </Match>
+</FindBugsFilter>

+ 57 - 50
src/main/java/com/owncloud/android/jobs/ContactsBackupJob.java

@@ -110,65 +110,60 @@ public class ContactsBackupJob extends Job {
 
     private void backupContact(Account account, String backupFolder) {
         ArrayList<String> vCard = new ArrayList<>();
-        try {
 
-            Cursor cursor = getContext().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null,
-                    null, null, null);
+        Cursor cursor = getContext().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null,
+                null, null, null);
 
-            if (cursor != null && cursor.getCount() > 0) {
-                cursor.moveToFirst();
-                for (int i = 0; i < cursor.getCount(); i++) {
+        if (cursor != null && cursor.getCount() > 0) {
+            cursor.moveToFirst();
+            for (int i = 0; i < cursor.getCount(); i++) {
 
-                    vCard.add(getContactFromCursor(cursor));
-                    cursor.moveToNext();
-                }
+                vCard.add(getContactFromCursor(cursor));
+                cursor.moveToNext();
             }
+        }
 
-            String filename = DateFormat.format("yyyy-MM-dd_HH-mm-ss", Calendar.getInstance()).toString() + ".vcf";
-            Log_OC.d(TAG, "Storing: " + filename);
-            File file = new File(getContext().getCacheDir(), filename);
+        String filename = DateFormat.format("yyyy-MM-dd_HH-mm-ss", Calendar.getInstance()).toString() + ".vcf";
+        Log_OC.d(TAG, "Storing: " + filename);
+        File file = new File(getContext().getCacheDir(), filename);
 
-            FileWriter fw = null;
-            try {
-                fw = new FileWriter(file);
+        FileWriter fw = null;
+        try {
+            fw = new FileWriter(file);
 
-                for (String card : vCard) {
-                    fw.write(card);
-                }
+            for (String card : vCard) {
+                fw.write(card);
+            }
 
-            } catch (IOException e) {
-                Log_OC.d(TAG, "Error ", e);
-            } finally {
-                if (cursor != null) {
-                    cursor.close();
-                }
-                
-                if (fw != null) {
-                    try {
-                        fw.close();
-                    } catch (IOException e) {
-                        Log_OC.d(TAG, "Error closing file writer ", e);
-                    }
-                }
+        } catch (IOException e) {
+            Log_OC.d(TAG, "Error ", e);
+        } finally {
+            if (cursor != null) {
+                cursor.close();
             }
 
-            FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
-            requester.uploadNewFile(
-                    getContext(),
-                    account,
-                    file.getAbsolutePath(),
-                    backupFolder + filename,
-                    FileUploader.LOCAL_BEHAVIOUR_MOVE,
-                    null,
-                    true,
-                    UploadFileOperation.CREATED_BY_USER,
-                    false,
-                    false
-            );
-
-        } catch (Exception e) {
-            Log_OC.d(TAG, e.getMessage());
+            if (fw != null) {
+                try {
+                    fw.close();
+                } catch (IOException e) {
+                    Log_OC.d(TAG, "Error closing file writer ", e);
+                }
+            }
         }
+
+        FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
+        requester.uploadNewFile(
+                getContext(),
+                account,
+                file.getAbsolutePath(),
+                backupFolder + filename,
+                FileUploader.LOCAL_BEHAVIOUR_MOVE,
+                null,
+                true,
+                UploadFileOperation.CREATED_BY_USER,
+                false,
+                false
+        );
     }
 
     private void expireFiles(Integer daysToExpire, String backupFolderString, Account account) {
@@ -209,9 +204,10 @@ public class ContactsBackupJob extends Job {
         Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
 
         String vCard = "";
+        InputStream inputStream = null;
+        InputStreamReader inputStreamReader = null;
         try {
-            InputStream inputStream = getContext().getContentResolver().openInputStream(uri);
-            InputStreamReader inputStreamReader;
+            inputStream = getContext().getContentResolver().openInputStream(uri);
             char[] buffer = new char[1024];
             StringBuilder stringBuilder = new StringBuilder();
 
@@ -235,6 +231,17 @@ public class ContactsBackupJob extends Job {
 
         } catch (IOException e) {
             Log_OC.d(TAG, e.getMessage());
+        } finally {
+            try {
+                if (inputStream != null) {
+                    inputStream.close();
+                }
+                if (inputStreamReader != null) {
+                    inputStreamReader.close();
+                }
+            } catch (IOException e) {
+                Log_OC.e(TAG, "failed to close stream");
+            }
         }
         return vCard;
     }

+ 0 - 33
src/main/java/com/owncloud/android/ui/adapter/GroupAdapter.java

@@ -1,33 +0,0 @@
-/**
- *   ownCloud Android client application
- *
- *   Copyright (C) 2015  ownCloud Inc.
- *
- *   This program is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License version 2,
- *   as published by the Free Software Foundation.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-package com.owncloud.android.ui.adapter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class GroupAdapter {
-
-    public String string;
-    public final List<String> children = new ArrayList<String>();
-
-    public GroupAdapter(String string) {
-        this.string = string;
-    }
-
-}

+ 1 - 1
src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java

@@ -67,7 +67,7 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
     public static final String SUCCESS = "SUCCESS";
     public static final int SETUP_ENCRYPTION_RESULT_CODE = 101;
     public static final int SETUP_ENCRYPTION_REQUEST_CODE = 100;
-    public static String SETUP_ENCRYPTION_DIALOG_TAG = "SETUP_ENCRYPTION_DIALOG_TAG";
+    public static final String SETUP_ENCRYPTION_DIALOG_TAG = "SETUP_ENCRYPTION_DIALOG_TAG";
     public static final String ARG_POSITION = "ARG_POSITION";
 
     private static String ARG_ACCOUNT = "ARG_ACCOUNT";

+ 0 - 2
src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java

@@ -774,8 +774,6 @@ public class ExtendedListFragment extends Fragment
             maxColumnSize = maxColumnSizeLandscape;
         } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
             maxColumnSize = maxColumnSizePortrait;
-        } else {
-            maxColumnSize = maxColumnSizePortrait;
         }
 
         if (isGridEnabled() && getColumnSize() > maxColumnSize) {

+ 2 - 2
src/main/java/com/owncloud/android/utils/FilesSyncHelper.java

@@ -73,7 +73,7 @@ public class FilesSyncHelper {
     public static final String GLOBAL = "global";
     public static final String SYNCEDFOLDERINITIATED = "syncedFolderIntitiated_";
 
-    public static int ContentSyncJobId = 315;
+    public static final int ContentSyncJobId = 315;
 
     public static void insertAllDBEntriesForSyncedFolder(SyncedFolder syncedFolder) {
         final Context context = MainApp.getAppContext();
@@ -126,7 +126,7 @@ public class FilesSyncHelper {
 
                     Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
                         @Override
-                        public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
+                        public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) {
 
                             File file = path.toFile();
                             if (attrs.lastModifiedTime().toMillis() >= Long.parseLong(dateInitiated) * 1000) {