Эх сурвалжийг харах

refactorings

Drone: update FindBugs results to reflect reduced error/warning count [skip ci]

Signed-off-by: nextcloud-android-bot <android@nextcloud.com>
David Luhmer 5 жил өмнө
parent
commit
d4bc9b3cf2

+ 1 - 1
scripts/analysis/findbugs-results.txt

@@ -1 +1 @@
-382
+381

+ 39 - 28
src/main/java/com/nextcloud/android/sso/InputStreamBinder.java

@@ -104,16 +104,6 @@ public class InputStreamBinder extends IInputStreamService.Stub {
         this.accountManager = accountManager;
         this.accountManager = accountManager;
     }
     }
 
 
-    private NameValuePair[] convertMapToNVP(Map<String, String> map) {
-        NameValuePair[] nvp = new NameValuePair[map.size()];
-        int i = 0;
-        for (String key : map.keySet()) {
-            nvp[i] = new NameValuePair(key, map.get(key));
-            i++;
-        }
-        return nvp;
-    }
-
     public ParcelFileDescriptor performNextcloudRequestV2(ParcelFileDescriptor input) {
     public ParcelFileDescriptor performNextcloudRequestV2(ParcelFileDescriptor input) {
         return performNextcloudRequestAndBodyStreamV2(input, null);
         return performNextcloudRequestAndBodyStreamV2(input, null);
     }
     }
@@ -362,21 +352,19 @@ public class InputStreamBinder extends IInputStreamService.Stub {
         if (status >= HTTP_STATUS_CODE_OK && status < HTTP_STATUS_CODE_MULTIPLE_CHOICES) {
         if (status >= HTTP_STATUS_CODE_OK && status < HTTP_STATUS_CODE_MULTIPLE_CHOICES) {
             return method;
             return method;
         } else {
         } else {
-            StringBuilder total = new StringBuilder();
             InputStream inputStream = method.getResponseBodyAsStream();
             InputStream inputStream = method.getResponseBodyAsStream();
+            String total = "No response body";
+
             // If response body is available
             // If response body is available
             if (inputStream != null) {
             if (inputStream != null) {
-                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
-                String line = reader.readLine();
-                while (line != null) {
-                    total.append(line).append('\n');
-                    line = reader.readLine();
-                }
-                Log_OC.e(TAG, total.toString());
+                total = inputStreamToString(inputStream);
+                Log_OC.e(TAG, total);
             }
             }
+
+            method.releaseConnection();
             throw new IllegalStateException(EXCEPTION_HTTP_REQUEST_FAILED,
             throw new IllegalStateException(EXCEPTION_HTTP_REQUEST_FAILED,
                                             new IllegalStateException(String.valueOf(status),
                                             new IllegalStateException(String.valueOf(status),
-                                                                      new IllegalStateException(total.toString())));
+                                                                      new IllegalStateException(total)));
         }
         }
     }
     }
 
 
@@ -427,21 +415,19 @@ public class InputStreamBinder extends IInputStreamService.Stub {
         if (status >= HTTP_STATUS_CODE_OK && status < HTTP_STATUS_CODE_MULTIPLE_CHOICES) {
         if (status >= HTTP_STATUS_CODE_OK && status < HTTP_STATUS_CODE_MULTIPLE_CHOICES) {
             return new Response(method);
             return new Response(method);
         } else {
         } else {
-            StringBuilder total = new StringBuilder();
             InputStream inputStream = method.getResponseBodyAsStream();
             InputStream inputStream = method.getResponseBodyAsStream();
+            String total = "No response body";
+
             // If response body is available
             // If response body is available
             if (inputStream != null) {
             if (inputStream != null) {
-                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
-                String line = reader.readLine();
-                while (line != null) {
-                    total.append(line).append('\n');
-                    line = reader.readLine();
-                }
-                Log_OC.e(TAG, total.toString());
+                total = inputStreamToString(inputStream);
+                Log_OC.e(TAG, total);
             }
             }
+
+            method.releaseConnection();
             throw new IllegalStateException(EXCEPTION_HTTP_REQUEST_FAILED,
             throw new IllegalStateException(EXCEPTION_HTTP_REQUEST_FAILED,
                                             new IllegalStateException(String.valueOf(status),
                                             new IllegalStateException(String.valueOf(status),
-                                                                      new IllegalStateException(total.toString())));
+                                                                      new IllegalStateException(total)));
         }
         }
     }
     }
 
 
@@ -480,4 +466,29 @@ public class InputStreamBinder extends IInputStreamService.Stub {
         }
         }
         return result == 0;
         return result == 0;
     }
     }
+
+    private static String inputStreamToString(InputStream inputStream) {
+        try {
+            StringBuilder total = new StringBuilder();
+            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+            String line = reader.readLine();
+            while (line != null) {
+                total.append(line).append('\n');
+                line = reader.readLine();
+            }
+            return total.toString();
+        } catch (Exception e) {
+            return e.getMessage();
+        }
+    }
+
+    private static NameValuePair[] convertMapToNVP(Map<String, String> map) {
+        NameValuePair[] nvp = new NameValuePair[map.size()];
+        int i = 0;
+        for (String key : map.keySet()) {
+            nvp[i] = new NameValuePair(key, map.get(key));
+            i++;
+        }
+        return nvp;
+    }
 }
 }

+ 6 - 5
src/main/java/com/nextcloud/android/sso/aidl/ParcelFileDescriptorUtil.java

@@ -57,14 +57,14 @@ public final class ParcelFileDescriptorUtil {
         private final InputStream inputStream;
         private final InputStream inputStream;
         private final OutputStream outputStream;
         private final OutputStream outputStream;
         private final IThreadListener threadListener;
         private final IThreadListener threadListener;
-        private final HttpMethodBase method;
+        private final HttpMethodBase httpMethod;
 
 
         TransferThread(InputStream in, OutputStream out, IThreadListener listener, HttpMethodBase method) {
         TransferThread(InputStream in, OutputStream out, IThreadListener listener, HttpMethodBase method) {
             super("ParcelFileDescriptor Transfer Thread");
             super("ParcelFileDescriptor Transfer Thread");
             inputStream = in;
             inputStream = in;
             outputStream = out;
             outputStream = out;
             threadListener = listener;
             threadListener = listener;
-            this.method = method;
+            httpMethod = method;
             setDaemon(true);
             setDaemon(true);
         }
         }
 
 
@@ -79,7 +79,7 @@ public final class ParcelFileDescriptorUtil {
                 }
                 }
                 outputStream.flush(); // just to be safe
                 outputStream.flush(); // just to be safe
             } catch (IOException e) {
             } catch (IOException e) {
-                Log.e("TransferThread", "writing failed");
+                Log_OC.e(TAG, "writing failed: " + e.getMessage());
             } finally {
             } finally {
                 try {
                 try {
                     inputStream.close();
                     inputStream.close();
@@ -96,8 +96,9 @@ public final class ParcelFileDescriptorUtil {
                 threadListener.onThreadFinished(this);
                 threadListener.onThreadFinished(this);
             }
             }
 
 
-            if (method != null) {
-                method.releaseConnection();
+            if (httpMethod != null) {
+                Log_OC.i(TAG, "releaseConnection");
+                httpMethod.releaseConnection();
             }
             }
         }
         }
     }
     }