[openrtm-commit:02755] r1015 - trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/Extension/LocalService/nameservice_file

openrtm @ openrtm.org openrtm @ openrtm.org
2017年 8月 17日 (木) 16:40:20 JST


Author: t-katami
Date: 2017-08-17 16:40:20 +0900 (Thu, 17 Aug 2017)
New Revision: 1015

Modified:
   trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/Extension/LocalService/nameservice_file/FileNameservice.java
Log:
[compat,bugfix,->RELENG_1_2] Fixed the items pointed out by the static code analysis tool.

Modified: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/Extension/LocalService/nameservice_file/FileNameservice.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/Extension/LocalService/nameservice_file/FileNameservice.java	2017-08-17 06:35:41 UTC (rev 1014)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/Extension/LocalService/nameservice_file/FileNameservice.java	2017-08-17 07:40:20 UTC (rev 1015)
@@ -145,11 +145,13 @@
             if (!createDirectory(directory)) {
                 continue;
             }
+            FileWriter file = null;
+            BufferedWriter ofs = null;
             try {
                 String filename = filepath.getName();
                 rtcout.println(Logbuf.DEBUG,"file name: "+filename);
-                FileWriter file = new FileWriter(filepath);
-                BufferedWriter ofs = new BufferedWriter(file);
+                file = new FileWriter(filepath);
+                ofs = new BufferedWriter(file);
                 for (int i=0; i < ns_info.length; ++i) {
                     ofs.write(ns_info[i]);
                 }
@@ -164,6 +166,24 @@
                 rtcout.println(Logbuf.ERROR,"Creating file has been failed. "
                                  + filepath);
             }
+            if(ofs != null){
+                try{
+                    ofs.close();
+                }
+                catch (Exception ex) {
+                    rtcout.println(Logbuf.ERROR,"closed file has been failed. "
+                                 + filepath);
+                }
+            }
+            if(file != null){
+                try{
+                    file.close();
+                }
+                catch (Exception ex) {
+                    rtcout.println(Logbuf.ERROR,"closed file has been failed. "
+                                 + filepath);
+                }
+            }
         }
     }
     



More information about the openrtm-commit mailing list