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

(cherry picked from commit 67e8489ac6)
This commit is contained in:
Akira Ajisaka 2016-03-02 00:20:57 +09:00
parent f1236c5d7c
commit aa896c767c
4 changed files with 57 additions and 65 deletions

View File

@ -1065,6 +1065,8 @@ Release 2.8.0 - UNRELEASED
ProviderUtils.excludeIncompatibleCredentialProviders. ProviderUtils.excludeIncompatibleCredentialProviders.
(Larry McCay via cnauroth) (Larry McCay via cnauroth)
HADOOP-12843. Fix findbugs warnings in hadoop-common (branch-2). (aajisaka)
Release 2.7.3 - UNRELEASED Release 2.7.3 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -18,11 +18,14 @@
package org.apache.hadoop.record.compiler; package org.apache.hadoop.record.compiler;
import java.io.Writer;
import java.util.ArrayList; import java.util.ArrayList;
import java.io.File; import java.io.File;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import org.apache.commons.io.Charsets;
import org.apache.commons.io.output.FileWriterWithEncoding;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
/** /**
@ -43,10 +46,8 @@ class CGenerator extends CodeGenerator {
ArrayList<JRecord> rlist, String destDir, ArrayList<String> options) ArrayList<JRecord> rlist, String destDir, ArrayList<String> options)
throws IOException { throws IOException {
name = new File(destDir, (new File(name)).getName()).getAbsolutePath(); name = new File(destDir, (new File(name)).getName()).getAbsolutePath();
FileWriter cc = new FileWriter(name+".c"); try (Writer cc = new FileWriterWithEncoding(name+".c", Charsets.UTF_8);
try { Writer hh = new FileWriterWithEncoding(name+".h", Charsets.UTF_8)) {
FileWriter hh = new FileWriter(name+".h");
try {
hh.write("#ifndef __"+ hh.write("#ifndef __"+
StringUtils.toUpperCase(name).replace('.','_')+"__\n"); StringUtils.toUpperCase(name).replace('.','_')+"__\n");
hh.write("#define __"+ hh.write("#define __"+
@ -66,11 +67,6 @@ class CGenerator extends CodeGenerator {
hh.write("#endif //"+ hh.write("#endif //"+
StringUtils.toUpperCase(name).replace('.','_')+"__\n"); StringUtils.toUpperCase(name).replace('.','_')+"__\n");
} finally {
hh.close();
}
} finally {
cc.close();
} }
} }
} }

View File

@ -18,11 +18,14 @@
package org.apache.hadoop.record.compiler; package org.apache.hadoop.record.compiler;
import java.io.Writer;
import java.util.ArrayList; import java.util.ArrayList;
import java.io.File; import java.io.File;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import org.apache.commons.io.Charsets;
import org.apache.commons.io.output.FileWriterWithEncoding;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
/** /**
@ -44,11 +47,8 @@ class CppGenerator extends CodeGenerator {
throws IOException { throws IOException {
name = new File(destDir, (new File(name)).getName()).getAbsolutePath(); name = new File(destDir, (new File(name)).getName()).getAbsolutePath();
FileWriter cc = new FileWriter(name+".cc"); try (Writer cc = new FileWriterWithEncoding(name+".cc", Charsets.UTF_8);
try { Writer hh = new FileWriterWithEncoding(name+".hh", Charsets.UTF_8)) {
FileWriter hh = new FileWriter(name+".hh");
try {
String fileName = (new File(name)).getName(); String fileName = (new File(name)).getName();
hh.write("#ifndef __"+ hh.write("#ifndef __"+
StringUtils.toUpperCase(fileName).replace('.','_')+"__\n"); StringUtils.toUpperCase(fileName).replace('.','_')+"__\n");
@ -69,11 +69,6 @@ class CppGenerator extends CodeGenerator {
hh.write("#endif //"+ hh.write("#endif //"+
StringUtils.toUpperCase(fileName).replace('.','_')+"__\n"); StringUtils.toUpperCase(fileName).replace('.','_')+"__\n");
} finally {
hh.close();
}
} finally {
cc.close();
} }
} }
} }

View File

@ -19,10 +19,12 @@
package org.apache.hadoop.record.compiler; package org.apache.hadoop.record.compiler;
import java.io.File; import java.io.File;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.Writer;
import java.util.*; 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.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
@ -469,11 +471,8 @@ public class JRecord extends JCompType {
cb.append("}\n"); cb.append("}\n");
cb.append("}\n"); cb.append("}\n");
FileWriter jj = new FileWriter(jfile); try (Writer jj = new FileWriterWithEncoding(jfile, Charsets.UTF_8)) {
try {
jj.write(cb.toString()); jj.write(cb.toString());
} finally {
jj.close();
} }
} }
} }
@ -545,7 +544,7 @@ public class JRecord extends JCompType {
cb.append("}\n"); cb.append("}\n");
} }
void genCode(FileWriter hh, FileWriter cc, ArrayList<String> options) void genCode(Writer hh, Writer cc, ArrayList<String> options)
throws IOException { throws IOException {
CodeBuffer hb = new CodeBuffer(); CodeBuffer hb = new CodeBuffer();
@ -810,7 +809,7 @@ public class JRecord extends JCompType {
return signature; return signature;
} }
void genCppCode(FileWriter hh, FileWriter cc, ArrayList<String> options) void genCppCode(Writer hh, Writer cc, ArrayList<String> options)
throws IOException { throws IOException {
((CppRecord)getCppType()).genCode(hh, cc, options); ((CppRecord)getCppType()).genCode(hh, cc, options);
} }