瀏覽代碼

HADOOP-6489. Fix 3 findbugs warnings. Contributed by Erik Steffl.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@899856 13f79535-47bb-0310-9956-ffa450edef68
Suresh Srinivas 15 年之前
父節點
當前提交
a90d3205d2

+ 2 - 0
CHANGES.txt

@@ -137,6 +137,8 @@ Trunk (unreleased changes)
     HADOOP-6402. testConf.xsl is not well-formed XML. (Steve Loughran
     HADOOP-6402. testConf.xsl is not well-formed XML. (Steve Loughran
     via tomwhite)
     via tomwhite)
 
 
+    HADOOP-6489. Fix 3 findbugs warnings. (Erik Steffl via suresh)
+
 Release 0.21.0 - Unreleased
 Release 0.21.0 - Unreleased
 
 
   INCOMPATIBLE CHANGES
   INCOMPATIBLE CHANGES

+ 1 - 1
src/java/org/apache/hadoop/fs/FileContext.java

@@ -156,6 +156,7 @@ public final class FileContext {
   
   
   public static final Log LOG = LogFactory.getLog(FileContext.class);
   public static final Log LOG = LogFactory.getLog(FileContext.class);
   public static final FsPermission DEFAULT_PERM = FsPermission.getDefault();
   public static final FsPermission DEFAULT_PERM = FsPermission.getDefault();
+  volatile private static FileContext localFsSingleton = null;
   
   
   /**
   /**
    * List of files that should be deleted on JVM shutdown.
    * List of files that should be deleted on JVM shutdown.
@@ -342,7 +343,6 @@ public final class FileContext {
     return getFileContext(new Configuration());
     return getFileContext(new Configuration());
   } 
   } 
   
   
-  private static FileContext localFsSingleton = null;
   /**
   /**
    * 
    * 
    * @return a FileContext for the local filesystem using the default config.
    * @return a FileContext for the local filesystem using the default config.

+ 29 - 20
src/java/org/apache/hadoop/io/compress/CompressionCodecFactory.java

@@ -199,29 +199,38 @@ public class CompressionCodecFactory {
           System.out.println("Codec for " + args[i] + " not found.");
           System.out.println("Codec for " + args[i] + " not found.");
         } else { 
         } else { 
           if (encode) {
           if (encode) {
-            CompressionOutputStream out = 
-              codec.createOutputStream(new java.io.FileOutputStream(args[i]));
-            byte[] buffer = new byte[100];
-            String inFilename = removeSuffix(args[i], 
-                                             codec.getDefaultExtension());
-            java.io.InputStream in = new java.io.FileInputStream(inFilename);
-            int len = in.read(buffer);
-            while (len > 0) {
-              out.write(buffer, 0, len);
-              len = in.read(buffer);
+            CompressionOutputStream out = null;
+            java.io.InputStream in = null;
+            try {
+              out = codec.createOutputStream(
+                  new java.io.FileOutputStream(args[i]));
+              byte[] buffer = new byte[100];
+              String inFilename = removeSuffix(args[i], 
+                  codec.getDefaultExtension());
+              in = new java.io.FileInputStream(inFilename);
+              int len = in.read(buffer);
+              while (len > 0) {
+                out.write(buffer, 0, len);
+                len = in.read(buffer);
+              }
+            } finally {
+              if(out != null) { out.close(); }
+              if(in  != null) { in.close(); }
             }
             }
-            in.close();
-            out.close();
           } else {
           } else {
-            CompressionInputStream in = 
-              codec.createInputStream(new java.io.FileInputStream(args[i]));
-            byte[] buffer = new byte[100];
-            int len = in.read(buffer);
-            while (len > 0) {
-              System.out.write(buffer, 0, len);
-              len = in.read(buffer);
+            CompressionInputStream in = null;
+            try {
+              in = codec.createInputStream(
+                  new java.io.FileInputStream(args[i]));
+              byte[] buffer = new byte[100];
+              int len = in.read(buffer);
+              while (len > 0) {
+                System.out.write(buffer, 0, len);
+                len = in.read(buffer);
+              }
+            } finally {
+              if(in != null) { in.close(); }
             }
             }
-            in.close();
           }
           }
         }
         }
       }
       }

+ 1 - 1
src/java/org/apache/hadoop/util/ReflectionUtils.java

@@ -47,7 +47,7 @@ import org.apache.hadoop.io.serializer.SerializerBase;
 public class ReflectionUtils {
 public class ReflectionUtils {
     
     
   private static final Class<?>[] EMPTY_ARRAY = new Class[]{};
   private static final Class<?>[] EMPTY_ARRAY = new Class[]{};
-  private static SerializationFactory serialFactory = null;
+  volatile private static SerializationFactory serialFactory = null;
 
 
   /** 
   /** 
    * Cache of constructors for each class. Pins the classes so they
    * Cache of constructors for each class. Pins the classes so they