You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by pe...@apache.org on 2022/06/24 08:17:50 UTC

[incubator-linkis] branch dev-1.2.0 updated: FileWriter and BufferedWriter are not closed in finally clause (#2334)

This is an automated email from the ASF dual-hosted git repository.

peacewong pushed a commit to branch dev-1.2.0
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git


The following commit(s) were added to refs/heads/dev-1.2.0 by this push:
     new 1c1ac0d33  FileWriter and BufferedWriter are not closed in finally clause (#2334)
1c1ac0d33 is described below

commit 1c1ac0d3334ddfc6fa72d8afbe2e236f56cc35c4
Author: Dlimeng <me...@gmail.com>
AuthorDate: Fri Jun 24 16:17:45 2022 +0800

     FileWriter and BufferedWriter are not closed in finally clause (#2334)
---
 .../test/test_multiuser/TestCreateContext.java     | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-client/src/test/java/org/apache/linkis/cs/client/test/test_multiuser/TestCreateContext.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-client/src/test/java/org/apache/linkis/cs/client/test/test_multiuser/TestCreateContext.java
index 17baf4fe6..b9d8f228f 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-client/src/test/java/org/apache/linkis/cs/client/test/test_multiuser/TestCreateContext.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-client/src/test/java/org/apache/linkis/cs/client/test/test_multiuser/TestCreateContext.java
@@ -45,6 +45,8 @@ public class TestCreateContext {
 
         // 1, create contextid
         ContextClient contextClient = ContextClientFactory.getOrCreateContextClient();
+        FileWriter fr = null;
+        BufferedWriter bw = null;
         try {
 
             Context context =
@@ -58,11 +60,10 @@ public class TestCreateContext {
             if (serializationHelper.accepts(contextID)) {
                 contextIDStr = serializationHelper.serialize(contextID);
                 File file = new File(CONTEXTID_PATH);
-                FileWriter fr = new FileWriter(file);
-                BufferedWriter bw = new BufferedWriter(fr);
+                fr = new FileWriter(file);
+                bw = new BufferedWriter(fr);
                 bw.write(contextIDStr);
                 bw.flush();
-                bw.close();
                 System.out.println("ContextID saved at : " + file.getAbsolutePath());
                 // test deserialize
                 System.out.println("contextIDStr: " + contextIDStr);
@@ -102,6 +103,21 @@ public class TestCreateContext {
         } catch (Exception e) {
             contextClient.close();
             e.printStackTrace();
+        } finally {
+            if (fr != null) {
+                try {
+                    fr.close();
+                } catch (Exception e) {
+                    // ignore
+                }
+            }
+            if (bw != null) {
+                try {
+                    bw.close();
+                } catch (Exception e) {
+                    // ignore
+                }
+            }
         }
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org