瀏覽代碼

Merge pull request #1883 from nextcloud/codacy

Fix further codacy issues
Mario Đanić 7 年之前
父節點
當前提交
c4e6c3a172

+ 1 - 0
src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -1117,6 +1117,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 uri = DisplayUtils.convertIdn(uri, true);
             } catch (IllegalArgumentException ex) {
                 // Let Owncloud library check the error of the malformed URI
+                Log_OC.e(TAG, "Error converting internationalized domain name " + uri, ex);
             }
 
             if (mHostUrlInput != null) {

+ 3 - 0
src/main/java/com/owncloud/android/media/MediaControlView.java

@@ -39,6 +39,7 @@ import android.widget.SeekBar.OnSeekBarChangeListener;
 import android.widget.TextView;
 
 import com.owncloud.android.R;
+import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.utils.ThemeUtils;
 
 import java.util.Formatter;
@@ -56,6 +57,7 @@ import java.util.Locale;
  */
 
 public class MediaControlView extends FrameLayout /* implements OnLayoutChangeListener, OnTouchListener */ implements OnClickListener, OnSeekBarChangeListener {
+    private static final String TAG = MediaControlView.class.getSimpleName();
 
     private MediaPlayerControl mPlayer;
     private Context mContext;
@@ -256,6 +258,7 @@ public class MediaControlView extends FrameLayout /* implements OnLayoutChangeLi
             // the canPause/canSeekXYZ methods. This is OK, it just means we
             // assume the media can be paused and seeked, and so we don't disable
             // the buttons.
+            Log_OC.i(TAG, "Old media interface detected");
         }
     }
 

+ 15 - 13
src/main/java/com/owncloud/android/operations/OAuth2GetAccessToken.java

@@ -1,4 +1,4 @@
-/**
+/*
  *   ownCloud Android client application
  *
  *   Copyright (C) 2015 ownCloud Inc.
@@ -54,7 +54,7 @@ public class OAuth2GetAccessToken extends RemoteOperation {
         mRedirectUri = redirectUri;
         mGrantType = grantType;
         mOAuth2AuthorizationResponse = oAuth2AuthorizationResponse;
-        mOAuth2ParsedAuthorizationResponse = new HashMap<String, String>();
+        mOAuth2ParsedAuthorizationResponse = new HashMap<>();
         mResultTokenMap = null;
     }
 
@@ -90,7 +90,7 @@ public class OAuth2GetAccessToken extends RemoteOperation {
                 
                 postMethod = new PostMethod(client.getWebdavUri().toString());
                 postMethod.setRequestBody(nameValuePairs);
-                int status = client.executeMethod(postMethod);
+                client.executeMethod(postMethod);
                 
                 String response = postMethod.getResponseBodyAsString();
                 if (response != null && response.length() > 0) {
@@ -122,14 +122,16 @@ public class OAuth2GetAccessToken extends RemoteOperation {
 
             final String code = "code";
             final String oauth_token_request = "OAuth2 TOKEN REQUEST with auth code ";
-            if (result !=  null && result.isSuccess()) {
-                Log_OC.i(TAG, oauth_token_request + mOAuth2ParsedAuthorizationResponse.get(code) + " to " + client.getWebdavUri() + ": " + result.getLogMessage());
-            } else if (result.getException() != null) {
-                Log_OC.e(TAG, oauth_token_request + mOAuth2ParsedAuthorizationResponse.get(code) + " to " + client.getWebdavUri() + ": " + result.getLogMessage(), result.getException());
-            } else if (result.getCode() == ResultCode.OAUTH2_ERROR) {
-                Log_OC.e(TAG, oauth_token_request + mOAuth2ParsedAuthorizationResponse.get(code) + " to " + client.getWebdavUri() + ": " + ((mResultTokenMap != null) ? mResultTokenMap.get(OAuth2Constants.KEY_ERROR) : "NULL"));
-            } else {
-                Log_OC.e(TAG, oauth_token_request + mOAuth2ParsedAuthorizationResponse.get(code) + " to " + client.getWebdavUri() + ": " + result.getLogMessage());
+            if (result != null) {
+                if (result.isSuccess()) {
+                    Log_OC.i(TAG, oauth_token_request + mOAuth2ParsedAuthorizationResponse.get(code) + " to " + client.getWebdavUri() + ": " + result.getLogMessage());
+                } else if (result.getException() != null) {
+                    Log_OC.e(TAG, oauth_token_request + mOAuth2ParsedAuthorizationResponse.get(code) + " to " + client.getWebdavUri() + ": " + result.getLogMessage(), result.getException());
+                } else if (result.getCode() == ResultCode.OAUTH2_ERROR) {
+                    Log_OC.e(TAG, oauth_token_request + mOAuth2ParsedAuthorizationResponse.get(code) + " to " + client.getWebdavUri() + ": " + ((mResultTokenMap != null) ? mResultTokenMap.get(OAuth2Constants.KEY_ERROR) : "NULL"));
+                } else {
+                    Log_OC.e(TAG, oauth_token_request + mOAuth2ParsedAuthorizationResponse.get(code) + " to " + client.getWebdavUri() + ": " + result.getLogMessage());
+                }
             }
         }
         
@@ -141,7 +143,7 @@ public class OAuth2GetAccessToken extends RemoteOperation {
         String[] pairs = mOAuth2AuthorizationResponse.split("&");
         int i = 0;
         String key = "";
-        String value = "";
+        String value;
         while (pairs.length > i) {
             int j = 0;
             String[] part = pairs[i].split("=");
@@ -162,7 +164,7 @@ public class OAuth2GetAccessToken extends RemoteOperation {
 
 
     private void parseAccessTokenResult (JSONObject tokenJson) throws JSONException {
-        mResultTokenMap = new HashMap<String, String>();
+        mResultTokenMap = new HashMap<>();
         
         if (tokenJson.has(OAuth2Constants.KEY_ACCESS_TOKEN)) {
             mResultTokenMap.put(OAuth2Constants.KEY_ACCESS_TOKEN, tokenJson.getString(OAuth2Constants.KEY_ACCESS_TOKEN));

+ 1 - 0
src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -1294,6 +1294,7 @@ public class FileDisplayActivity extends HookActivity
                     DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
                 } catch (RuntimeException re) {
                     // we did not send this intent, so ignoring
+                    Log_OC.i(TAG, "Ignoring error deleting data");
                 }
             }
         }

+ 1 - 0
src/main/java/com/owncloud/android/ui/activity/LogHistoryActivity.java

@@ -245,6 +245,7 @@ public class LogHistoryActivity extends ToolbarActivity {
                         br.close();
                     } catch (IOException e) {
                         // ignore
+                        Log_OC.d(TAG, "Error closing log reader", e);
                     }
                 }
             }

+ 2 - 1
src/main/java/com/owncloud/android/ui/adapter/DiskLruImageCache.java

@@ -97,7 +97,8 @@ public class DiskLruImageCache {
                 if (editor != null) {
                     editor.abort();
                 }
-            } catch (IOException ignored) {
+            } catch (IOException ex) {
+                Log_OC.d(TAG, "Error aborting editor", ex);
             }
         }
     }

+ 3 - 2
src/test/java/com/owncloud/android/authentication/AuthenticatorDataUrlTest.java

@@ -31,8 +31,8 @@ import org.junit.runners.BlockJUnit4ClassRunner;
  */
 @RunWith(BlockJUnit4ClassRunner.class)
 public class AuthenticatorDataUrlTest {
-    public static final String URL_PARSING = " url parsing";
-    public static final String INCORRECT_USER_VALUE_IN = "Incorrect user value in ";
+    private static final String URL_PARSING = " url parsing";
+    private static final String INCORRECT_USER_VALUE_IN = "Incorrect user value in ";
     private String schemeUrl = "nextcloud://login/";
     private String plus = "&";
 
@@ -152,6 +152,7 @@ public class AuthenticatorDataUrlTest {
                 Assert.fail("Illegal Argument Exception expected!");
             } catch (IllegalArgumentException e) {
                 // all well
+                System.out.println("Error with " + urlStart + dataUrl);
             }
         }
     }