Selaa lähdekoodia

HADOOP-3036. Fix findbugs warnings in UpgradeUtilities. Contributed by Konstantin Shvachko


git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@638975 13f79535-47bb-0310-9956-ffa450edef68
Christopher Douglas 17 vuotta sitten
vanhempi
commit
7e4730a274
2 muutettua tiedostoa jossa 18 lisäystä ja 10 poistoa
  1. 3 0
      CHANGES.txt
  2. 15 10
      src/test/org/apache/hadoop/dfs/UpgradeUtilities.java

+ 3 - 0
CHANGES.txt

@@ -283,6 +283,9 @@ Trunk (unreleased changes)
     HADOOP-3030. Release reserved space for file in InMemoryFileSystem if
     checksum reservation fails. (Devaraj Das via cdouglas)
 
+    HADOOP-3036. Fix findbugs warnings in UpgradeUtilities. (Konstantin
+    Shvachko via cdouglas)
+
 Release 0.16.2 - Unreleased
 
   BUG FIXES

+ 15 - 10
src/test/org/apache/hadoop/dfs/UpgradeUtilities.java

@@ -52,7 +52,7 @@ public class UpgradeUtilities {
 
   // Root scratch directory on local filesystem 
   private static File TEST_ROOT_DIR = new File(
-                                               System.getProperty("test.build.data","/tmp").toString().replace(' ', '+'));
+      System.getProperty("test.build.data","/tmp").replace(' ', '+'));
   // The singleton master storage directory for Namenode
   private static File namenodeStorage = new File(TEST_ROOT_DIR, "namenodeMaster");
   // A checksum of the contents in namenodeStorage directory
@@ -207,20 +207,25 @@ public class UpgradeUtilities {
     Arrays.sort(list);
     CRC32 checksum = new CRC32();
     for (int i = 0; i < list.length; i++) {
-      if (list[i].isFile()) {
-        // skip VERSION file for DataNodes
-        if (nodeType == DATA_NODE &&
-            list[i].getName().equals("VERSION")) 
-          {
-            continue; 
-          }
-        FileInputStream fis = new FileInputStream(list[i]);
+      if (!list[i].isFile()) {
+        continue;
+      }
+      // skip VERSION file for DataNodes
+      if (nodeType == DATA_NODE && list[i].getName().equals("VERSION")) {
+        continue; 
+      }
+      FileInputStream fis = null;
+      try {
+        fis = new FileInputStream(list[i]);
         byte[] buffer = new byte[1024];
         int bytesRead;
         while ((bytesRead = fis.read(buffer)) != -1) {
           checksum.update(buffer, 0, bytesRead);
         }
-        fis.close();
+      } finally {
+        if(fis != null) {
+          fis.close();
+        }
       }
     }
     return checksum.getValue();