You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by aa...@apache.org on 2016/03/01 16:22:59 UTC

hadoop git commit: HADOOP-12843. Fix findbugs warnings in hadoop-common (branch-2). (aajisaka)

Repository: hadoop
Updated Branches:
  refs/heads/branch-2 e402371b6 -> 67e8489ac


HADOOP-12843. Fix findbugs warnings in hadoop-common (branch-2). (aajisaka)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/67e8489a
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/67e8489a
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/67e8489a

Branch: refs/heads/branch-2
Commit: 67e8489ac6df70e07d530017bb7ddee017e57e5b
Parents: e402371
Author: Akira Ajisaka <aa...@apache.org>
Authored: Wed Mar 2 00:20:57 2016 +0900
Committer: Akira Ajisaka <aa...@apache.org>
Committed: Wed Mar 2 00:20:57 2016 +0900

----------------------------------------------------------------------
 hadoop-common-project/hadoop-common/CHANGES.txt |  2 +
 .../hadoop/record/compiler/CGenerator.java      | 48 ++++++++---------
 .../hadoop/record/compiler/CppGenerator.java    | 55 +++++++++-----------
 .../apache/hadoop/record/compiler/JRecord.java  | 13 +++--
 4 files changed, 55 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/67e8489a/hadoop-common-project/hadoop-common/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt
index 346a910..300414b 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -1140,6 +1140,8 @@ Release 2.8.0 - UNRELEASED
     ProviderUtils.excludeIncompatibleCredentialProviders.
     (Larry McCay via cnauroth)
 
+    HADOOP-12843. Fix findbugs warnings in hadoop-common (branch-2). (aajisaka)
+
 Release 2.7.3 - UNRELEASED
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/hadoop/blob/67e8489a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/record/compiler/CGenerator.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/record/compiler/CGenerator.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/record/compiler/CGenerator.java
index e23f353..e175a69 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/record/compiler/CGenerator.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/record/compiler/CGenerator.java
@@ -18,11 +18,14 @@
 
 package org.apache.hadoop.record.compiler;
 
+import java.io.Writer;
 import java.util.ArrayList;
 import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.util.Iterator;
+
+import org.apache.commons.io.Charsets;
+import org.apache.commons.io.output.FileWriterWithEncoding;
 import org.apache.hadoop.util.StringUtils;
 
 /**
@@ -43,34 +46,27 @@ class CGenerator extends CodeGenerator {
                ArrayList<JRecord> rlist, String destDir, ArrayList<String> options)
     throws IOException {
     name = new File(destDir, (new File(name)).getName()).getAbsolutePath();
-    FileWriter cc = new FileWriter(name+".c");
-    try {
-      FileWriter hh = new FileWriter(name+".h");
-      try {
-        hh.write("#ifndef __"+
-            StringUtils.toUpperCase(name).replace('.','_')+"__\n");
-        hh.write("#define __"+
-            StringUtils.toUpperCase(name).replace('.','_')+"__\n");
-        hh.write("#include \"recordio.h\"\n");
-        for (Iterator<JFile> iter = ilist.iterator(); iter.hasNext();) {
-          hh.write("#include \""+iter.next().getName()+".h\"\n");
-        }
-
-        cc.write("#include \""+name+".h\"\n");
+    try (Writer cc = new FileWriterWithEncoding(name+".c", Charsets.UTF_8);
+         Writer hh = new FileWriterWithEncoding(name+".h", Charsets.UTF_8)) {
+      hh.write("#ifndef __"+
+          StringUtils.toUpperCase(name).replace('.','_')+"__\n");
+      hh.write("#define __"+
+          StringUtils.toUpperCase(name).replace('.','_')+"__\n");
+      hh.write("#include \"recordio.h\"\n");
+      for (Iterator<JFile> iter = ilist.iterator(); iter.hasNext();) {
+        hh.write("#include \""+iter.next().getName()+".h\"\n");
+      }
 
-        /*
-        for (Iterator<JRecord> iter = rlist.iterator(); iter.hasNext();) {
-        iter.next().genCppCode(hh, cc);
-        }
-         */
+      cc.write("#include \""+name+".h\"\n");
 
-        hh.write("#endif //"+
-            StringUtils.toUpperCase(name).replace('.','_')+"__\n");
-      } finally {
-        hh.close();
+      /*
+      for (Iterator<JRecord> iter = rlist.iterator(); iter.hasNext();) {
+      iter.next().genCppCode(hh, cc);
       }
-    } finally {
-      cc.close();
+       */
+
+      hh.write("#endif //"+
+          StringUtils.toUpperCase(name).replace('.','_')+"__\n");
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/67e8489a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/record/compiler/CppGenerator.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/record/compiler/CppGenerator.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/record/compiler/CppGenerator.java
index 081ae09..70a1359 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/record/compiler/CppGenerator.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/record/compiler/CppGenerator.java
@@ -18,11 +18,14 @@
 
 package org.apache.hadoop.record.compiler;
 
+import java.io.Writer;
 import java.util.ArrayList;
 import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.util.Iterator;
+
+import org.apache.commons.io.Charsets;
+import org.apache.commons.io.output.FileWriterWithEncoding;
 import org.apache.hadoop.util.StringUtils;
 
 /**
@@ -44,36 +47,28 @@ class CppGenerator extends CodeGenerator {
     throws IOException {
     name = new File(destDir, (new File(name)).getName()).getAbsolutePath();
 
-    FileWriter cc = new FileWriter(name+".cc");
-    try {
-      FileWriter hh = new FileWriter(name+".hh");
-      
-      try {
-        String fileName = (new File(name)).getName();
-        hh.write("#ifndef __"+
-            StringUtils.toUpperCase(fileName).replace('.','_')+"__\n");
-        hh.write("#define __"+
-            StringUtils.toUpperCase(fileName).replace('.','_')+"__\n");
-        hh.write("#include \"recordio.hh\"\n");
-        hh.write("#include \"recordTypeInfo.hh\"\n");
-        for (Iterator<JFile> iter = ilist.iterator(); iter.hasNext();) {
-          hh.write("#include \""+iter.next().getName()+".hh\"\n");
-        }
-        
-        cc.write("#include \""+fileName+".hh\"\n");
-        cc.write("#include \"utils.hh\"\n");
-        
-        for (Iterator<JRecord> iter = rlist.iterator(); iter.hasNext();) {
-          iter.next().genCppCode(hh, cc, options);
-        }
-        
-        hh.write("#endif //"+
-            StringUtils.toUpperCase(fileName).replace('.','_')+"__\n");
-      } finally {
-        hh.close();
+    try (Writer cc = new FileWriterWithEncoding(name+".cc", Charsets.UTF_8);
+         Writer hh = new FileWriterWithEncoding(name+".hh", Charsets.UTF_8)) {
+      String fileName = (new File(name)).getName();
+      hh.write("#ifndef __"+
+          StringUtils.toUpperCase(fileName).replace('.','_')+"__\n");
+      hh.write("#define __"+
+          StringUtils.toUpperCase(fileName).replace('.','_')+"__\n");
+      hh.write("#include \"recordio.hh\"\n");
+      hh.write("#include \"recordTypeInfo.hh\"\n");
+      for (Iterator<JFile> iter = ilist.iterator(); iter.hasNext();) {
+        hh.write("#include \""+iter.next().getName()+".hh\"\n");
       }
-    } finally {
-      cc.close();
+
+      cc.write("#include \""+fileName+".hh\"\n");
+      cc.write("#include \"utils.hh\"\n");
+
+      for (Iterator<JRecord> iter = rlist.iterator(); iter.hasNext();) {
+        iter.next().genCppCode(hh, cc, options);
+      }
+
+      hh.write("#endif //"+
+          StringUtils.toUpperCase(fileName).replace('.','_')+"__\n");
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/67e8489a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/record/compiler/JRecord.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/record/compiler/JRecord.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/record/compiler/JRecord.java
index 80e545b..2310538 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/record/compiler/JRecord.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/record/compiler/JRecord.java
@@ -19,10 +19,12 @@
 package org.apache.hadoop.record.compiler;
 
 import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
+import java.io.Writer;
 import java.util.*;
 
+import org.apache.commons.io.Charsets;
+import org.apache.commons.io.output.FileWriterWithEncoding;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 
@@ -469,11 +471,8 @@ public class JRecord extends JCompType {
       cb.append("}\n");
       cb.append("}\n");
 
-      FileWriter jj = new FileWriter(jfile);
-      try {
+      try (Writer jj = new FileWriterWithEncoding(jfile, Charsets.UTF_8)) {
         jj.write(cb.toString());
-      } finally {
-        jj.close();
       }
     }
   }
@@ -545,7 +544,7 @@ public class JRecord extends JCompType {
       cb.append("}\n");
     }
     
-    void genCode(FileWriter hh, FileWriter cc, ArrayList<String> options)
+    void genCode(Writer hh, Writer cc, ArrayList<String> options)
       throws IOException {
       CodeBuffer hb = new CodeBuffer();
       
@@ -810,7 +809,7 @@ public class JRecord extends JCompType {
     return signature;
   }
   
-  void genCppCode(FileWriter hh, FileWriter cc, ArrayList<String> options)
+  void genCppCode(Writer hh, Writer cc, ArrayList<String> options)
     throws IOException {
     ((CppRecord)getCppType()).genCode(hh, cc, options);
   }