From 5c874143909b7bf2372f58b898266ecd4f732c6a Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Tue, 2 Jun 2015 17:29:57 +0200 Subject: [PATCH 1/2] Close resource in finally block I don't quite get the reason for `mBuf` here as in `com.owncloud.android.lib.common.utils.Log_OC#appendLog` anyways a new `BufferedWriter` is started but it might make sense to close this here as this will otherwise cause warnings in static code scanners. Didn't test this as I don't have a Java device and so it requires extensive testing. --- .../owncloud/android/lib/common/utils/Log_OC.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/com/owncloud/android/lib/common/utils/Log_OC.java b/src/com/owncloud/android/lib/common/utils/Log_OC.java index 4d4760e6..c99c5e59 100644 --- a/src/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/src/com/owncloud/android/lib/common/utils/Log_OC.java @@ -60,7 +60,7 @@ public class Log_OC { } public static void w(String TAG, String message) { - Log.w(TAG,message); + Log.w(TAG, message); appendLog(TAG+" : "+ message); } @@ -99,8 +99,16 @@ public class Log_OC { } } catch (IOException e) { - e.printStackTrace(); - } + e.printStackTrace(); + } finally { + if(mBuf != null) { + try { + mBuf.close(); + } catch(IOException e) { + e.printStackTrace(); + } + } + } } /** From d39d26f842c7b997209986c034567fee97c38c84 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Wed, 3 Jun 2015 11:18:18 +0200 Subject: [PATCH 2/2] Close in finally block --- src/com/owncloud/android/lib/common/utils/Log_OC.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/com/owncloud/android/lib/common/utils/Log_OC.java b/src/com/owncloud/android/lib/common/utils/Log_OC.java index c99c5e59..2bef4fc9 100644 --- a/src/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/src/com/owncloud/android/lib/common/utils/Log_OC.java @@ -167,10 +167,15 @@ public class Log_OC { mBuf.newLine(); mBuf.write(text); mBuf.newLine(); - mBuf.close(); } catch (IOException e) { e.printStackTrace(); - } + } finally { + try { + mBuf.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } // Check if current log file size is bigger than the max file size defined if (mLogFile.length() > MAX_FILE_SIZE) {