YARN-2940. Fix new findbugs warnings in rest of the hadoop-yarn components. (Contributed by Li Lu)

(cherry picked from commit d468c9aaf1)
This commit is contained in:
Junping Du 2014-12-23 20:04:33 -08:00
parent e3a54b1b8b
commit 361fab14be
13 changed files with 71 additions and 39 deletions

View File

@ -243,6 +243,9 @@ Release 2.7.0 - UNRELEASED
YARN-2340. Fixed NPE when queue is stopped during RM restart. YARN-2340. Fixed NPE when queue is stopped during RM restart.
(Rohith Sharmaks via jianhe) (Rohith Sharmaks via jianhe)
YARN-2940. Fix new findbugs warnings in rest of the hadoop-yarn components. (Li Lu
via junping_du)
Release 2.6.0 - 2014-11-18 Release 2.6.0 - 2014-11-18
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -463,11 +463,11 @@ public class ApplicationMaster {
scriptPath = envs.get(DSConstants.DISTRIBUTEDSHELLSCRIPTLOCATION); scriptPath = envs.get(DSConstants.DISTRIBUTEDSHELLSCRIPTLOCATION);
if (envs.containsKey(DSConstants.DISTRIBUTEDSHELLSCRIPTTIMESTAMP)) { if (envs.containsKey(DSConstants.DISTRIBUTEDSHELLSCRIPTTIMESTAMP)) {
shellScriptPathTimestamp = Long.valueOf(envs shellScriptPathTimestamp = Long.parseLong(envs
.get(DSConstants.DISTRIBUTEDSHELLSCRIPTTIMESTAMP)); .get(DSConstants.DISTRIBUTEDSHELLSCRIPTTIMESTAMP));
} }
if (envs.containsKey(DSConstants.DISTRIBUTEDSHELLSCRIPTLEN)) { if (envs.containsKey(DSConstants.DISTRIBUTEDSHELLSCRIPTLEN)) {
shellScriptPathLen = Long.valueOf(envs shellScriptPathLen = Long.parseLong(envs
.get(DSConstants.DISTRIBUTEDSHELLSCRIPTLEN)); .get(DSConstants.DISTRIBUTEDSHELLSCRIPTLEN));
} }
if (!scriptPath.isEmpty() if (!scriptPath.isEmpty()

View File

@ -25,6 +25,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.InetAddress; import java.net.InetAddress;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Map; import java.util.Map;
@ -232,11 +233,11 @@ public class UnmanagedAMLauncher {
Process amProc = Runtime.getRuntime().exec(amCmd, envAMList.toArray(envAM)); Process amProc = Runtime.getRuntime().exec(amCmd, envAMList.toArray(envAM));
final BufferedReader errReader = final BufferedReader errReader =
new BufferedReader(new InputStreamReader(amProc new BufferedReader(new InputStreamReader(
.getErrorStream())); amProc.getErrorStream(), Charset.forName("UTF-8")));
final BufferedReader inReader = final BufferedReader inReader =
new BufferedReader(new InputStreamReader(amProc new BufferedReader(new InputStreamReader(
.getInputStream())); amProc.getInputStream(), Charset.forName("UTF-8")));
// read error and input streams as this would free up the buffers // read error and input streams as this would free up the buffers
// free the error stream buffer // free the error stream buffer

View File

@ -261,9 +261,8 @@ public class AMRMClientImpl<T extends ContainerRequest> extends AMRMClient<T> {
blacklistToRemove.addAll(blacklistRemovals); blacklistToRemove.addAll(blacklistRemovals);
ResourceBlacklistRequest blacklistRequest = ResourceBlacklistRequest blacklistRequest =
(blacklistToAdd != null) || (blacklistToRemove != null) ?
ResourceBlacklistRequest.newInstance(blacklistToAdd, ResourceBlacklistRequest.newInstance(blacklistToAdd,
blacklistToRemove) : null; blacklistToRemove);
allocateRequest = allocateRequest =
AllocateRequest.newInstance(lastResponseId, progressIndicator, AllocateRequest.newInstance(lastResponseId, progressIndicator,

View File

@ -19,7 +19,9 @@ package org.apache.hadoop.yarn.client.cli;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
@ -276,7 +278,8 @@ public class ApplicationCLI extends YarnCLI {
} }
// Use PrintWriter.println, which uses correct platform line ending. // Use PrintWriter.println, which uses correct platform line ending.
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter appAttemptReportStr = new PrintWriter(baos); PrintWriter appAttemptReportStr = new PrintWriter(
new OutputStreamWriter(baos, Charset.forName("UTF-8")));
if (appAttemptReport != null) { if (appAttemptReport != null) {
appAttemptReportStr.println("Application Attempt Report : "); appAttemptReportStr.println("Application Attempt Report : ");
appAttemptReportStr.print("\tApplicationAttempt-Id : "); appAttemptReportStr.print("\tApplicationAttempt-Id : ");
@ -335,7 +338,8 @@ public class ApplicationCLI extends YarnCLI {
} }
// Use PrintWriter.println, which uses correct platform line ending. // Use PrintWriter.println, which uses correct platform line ending.
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter containerReportStr = new PrintWriter(baos); PrintWriter containerReportStr = new PrintWriter(
new OutputStreamWriter(baos, Charset.forName("UTF-8")));
if (containerReport != null) { if (containerReport != null) {
containerReportStr.println("Container Report : "); containerReportStr.println("Container Report : ");
containerReportStr.print("\tContainer-Id : "); containerReportStr.print("\tContainer-Id : ");
@ -376,7 +380,8 @@ public class ApplicationCLI extends YarnCLI {
private void listApplications(Set<String> appTypes, private void listApplications(Set<String> appTypes,
EnumSet<YarnApplicationState> appStates) throws YarnException, EnumSet<YarnApplicationState> appStates) throws YarnException,
IOException { IOException {
PrintWriter writer = new PrintWriter(sysout); PrintWriter writer = new PrintWriter(
new OutputStreamWriter(sysout, Charset.forName("UTF-8")));
if (allAppStates) { if (allAppStates) {
for (YarnApplicationState appState : YarnApplicationState.values()) { for (YarnApplicationState appState : YarnApplicationState.values()) {
appStates.add(appState); appStates.add(appState);
@ -478,7 +483,8 @@ public class ApplicationCLI extends YarnCLI {
} }
// Use PrintWriter.println, which uses correct platform line ending. // Use PrintWriter.println, which uses correct platform line ending.
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter appReportStr = new PrintWriter(baos); PrintWriter appReportStr = new PrintWriter(
new OutputStreamWriter(baos, Charset.forName("UTF-8")));
if (appReport != null) { if (appReport != null) {
appReportStr.println("Application Report : "); appReportStr.println("Application Report : ");
appReportStr.print("\tApplication-Id : "); appReportStr.print("\tApplication-Id : ");
@ -554,7 +560,8 @@ public class ApplicationCLI extends YarnCLI {
*/ */
private void listApplicationAttempts(String applicationId) throws YarnException, private void listApplicationAttempts(String applicationId) throws YarnException,
IOException { IOException {
PrintWriter writer = new PrintWriter(sysout); PrintWriter writer = new PrintWriter(
new OutputStreamWriter(sysout, Charset.forName("UTF-8")));
List<ApplicationAttemptReport> appAttemptsReport = client List<ApplicationAttemptReport> appAttemptsReport = client
.getApplicationAttempts(ConverterUtils.toApplicationId(applicationId)); .getApplicationAttempts(ConverterUtils.toApplicationId(applicationId));
@ -580,7 +587,8 @@ public class ApplicationCLI extends YarnCLI {
*/ */
private void listContainers(String appAttemptId) throws YarnException, private void listContainers(String appAttemptId) throws YarnException,
IOException { IOException {
PrintWriter writer = new PrintWriter(sysout); PrintWriter writer = new PrintWriter(
new OutputStreamWriter(sysout, Charset.forName("UTF-8")));
List<ContainerReport> appsReport = client List<ContainerReport> appsReport = client
.getContainers(ConverterUtils.toApplicationAttemptId(appAttemptId)); .getContainers(ConverterUtils.toApplicationAttemptId(appAttemptId));

View File

@ -19,7 +19,9 @@ package org.apache.hadoop.yarn.client.cli;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
@ -141,7 +143,8 @@ public class NodeCLI extends YarnCLI {
*/ */
private void listClusterNodes(Set<NodeState> nodeStates) private void listClusterNodes(Set<NodeState> nodeStates)
throws YarnException, IOException { throws YarnException, IOException {
PrintWriter writer = new PrintWriter(sysout); PrintWriter writer = new PrintWriter(
new OutputStreamWriter(sysout, Charset.forName("UTF-8")));
List<NodeReport> nodesReport = client.getNodeReports( List<NodeReport> nodesReport = client.getNodeReports(
nodeStates.toArray(new NodeState[0])); nodeStates.toArray(new NodeState[0]));
writer.println("Total Nodes:" + nodesReport.size()); writer.println("Total Nodes:" + nodesReport.size());
@ -167,7 +170,8 @@ public class NodeCLI extends YarnCLI {
List<NodeReport> nodesReport = client.getNodeReports(); List<NodeReport> nodesReport = client.getNodeReports();
// Use PrintWriter.println, which uses correct platform line ending. // Use PrintWriter.println, which uses correct platform line ending.
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter nodeReportStr = new PrintWriter(baos); PrintWriter nodeReportStr = new PrintWriter(
new OutputStreamWriter(baos, Charset.forName("UTF-8")));
NodeReport nodeReport = null; NodeReport nodeReport = null;
for (NodeReport report : nodesReport) { for (NodeReport report : nodesReport) {
if (!report.getNodeId().equals(nodeId)) { if (!report.getNodeId().equals(nodeId)) {

View File

@ -18,7 +18,9 @@
package org.apache.hadoop.yarn.client.cli; package org.apache.hadoop.yarn.client.cli;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Set; import java.util.Set;
@ -102,7 +104,8 @@ public class QueueCLI extends YarnCLI {
*/ */
private int listQueue(String queueName) throws YarnException, IOException { private int listQueue(String queueName) throws YarnException, IOException {
int rc; int rc;
PrintWriter writer = new PrintWriter(sysout); PrintWriter writer = new PrintWriter(
new OutputStreamWriter(sysout, Charset.forName("UTF-8")));
QueueInfo queueInfo = client.getQueueInfo(queueName); QueueInfo queueInfo = client.getQueueInfo(queueName);
if (queueInfo != null) { if (queueInfo != null) {

View File

@ -491,7 +491,10 @@ public class CuratorService extends CompositeService
public boolean zkPathExists(String path) throws IOException { public boolean zkPathExists(String path) throws IOException {
checkServiceLive(); checkServiceLive();
try { try {
return zkStat(path) != null; // if zkStat(path) returns without throwing an exception, the return value
// is guaranteed to be not null
zkStat(path);
return true;
} catch (PathNotFoundException e) { } catch (PathNotFoundException e) {
return false; return false;
} catch (IOException e) { } catch (IOException e) {

View File

@ -592,17 +592,17 @@ public class RegistrySecurity extends AbstractService {
* Note the semicolon on the last entry * Note the semicolon on the last entry
*/ */
private static final String JAAS_ENTRY = private static final String JAAS_ENTRY =
"%s { \n" "%s { %n"
+ " %s required\n" + " %s required%n"
// kerberos module // kerberos module
+ " keyTab=\"%s\"\n" + " keyTab=\"%s\"%n"
+ " debug=true\n" + " debug=true%n"
+ " principal=\"%s\"\n" + " principal=\"%s\"%n"
+ " useKeyTab=true\n" + " useKeyTab=true%n"
+ " useTicketCache=false\n" + " useTicketCache=false%n"
+ " doNotPrompt=true\n" + " doNotPrompt=true%n"
+ " storeKey=true;\n" + " storeKey=true;%n"
+ "}; \n" + "}; %n"
; ;
/** /**

View File

@ -217,9 +217,9 @@ public class RegistryAdminService extends RegistryOperationsService {
String message = String.format(Locale.ENGLISH, String message = String.format(Locale.ENGLISH,
"Failed to create root paths {%s};" + "Failed to create root paths {%s};" +
"\ndiagnostics={%s}" + "%ndiagnostics={%s}" +
"\ncurrent registry is:" + "%ncurrent registry is:" +
"\n{%s}", "%n{%s}",
e, e,
bindingDiagnosticDetails(), bindingDiagnosticDetails(),
dumpRegistryRobustly(true)); dumpRegistryRobustly(true));

View File

@ -19,6 +19,7 @@
package org.apache.hadoop.yarn.lib; package org.apache.hadoop.yarn.lib;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List; import java.util.List;
import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.CreateMode;
@ -55,8 +56,8 @@ public class ZKClient {
public void registerService(String path, String data) throws public void registerService(String path, String data) throws
IOException, InterruptedException { IOException, InterruptedException {
try { try {
zkClient.create(path, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, zkClient.create(path, data.getBytes(Charset.forName("UTF-8")),
CreateMode.EPHEMERAL); ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
} catch(KeeperException ke) { } catch(KeeperException ke) {
throw new IOException(ke); throw new IOException(ke);
} }
@ -109,7 +110,7 @@ public class ZKClient {
try { try {
Stat stat = new Stat(); Stat stat = new Stat();
byte[] byteData = zkClient.getData(path, false, stat); byte[] byteData = zkClient.getData(path, false, stat);
data = new String(byteData); data = new String(byteData, Charset.forName("UTF-8"));
} catch(KeeperException ke) { } catch(KeeperException ke) {
throw new IOException(ke); throw new IOException(ke);
} }

View File

@ -118,7 +118,7 @@ public class BuilderUtils {
public static ApplicationId newApplicationId(RecordFactory recordFactory, public static ApplicationId newApplicationId(RecordFactory recordFactory,
long clustertimestamp, CharSequence id) { long clustertimestamp, CharSequence id) {
return ApplicationId.newInstance(clustertimestamp, return ApplicationId.newInstance(clustertimestamp,
Integer.valueOf(id.toString())); Integer.parseInt(id.toString()));
} }
public static ApplicationId newApplicationId(RecordFactory recordFactory, public static ApplicationId newApplicationId(RecordFactory recordFactory,
@ -137,7 +137,7 @@ public class BuilderUtils {
public static ApplicationId convert(long clustertimestamp, CharSequence id) { public static ApplicationId convert(long clustertimestamp, CharSequence id) {
return ApplicationId.newInstance(clustertimestamp, return ApplicationId.newInstance(clustertimestamp,
Integer.valueOf(id.toString())); Integer.parseInt(id.toString()));
} }
public static ContainerId newContainerId(ApplicationAttemptId appAttemptId, public static ContainerId newContainerId(ApplicationAttemptId appAttemptId,

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.ObjectInputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -68,9 +69,9 @@ public class WebAppProxyServlet extends HttpServlet {
public static final String PROXY_USER_COOKIE_NAME = "proxy-user"; public static final String PROXY_USER_COOKIE_NAME = "proxy-user";
private final List<TrackingUriPlugin> trackingUriPlugins; private transient List<TrackingUriPlugin> trackingUriPlugins;
private final String rmAppPageUrlBase; private final String rmAppPageUrlBase;
private final transient YarnConfiguration conf; private transient YarnConfiguration conf;
private static class _ implements Hamlet._ { private static class _ implements Hamlet._ {
//Empty //Empty
@ -350,4 +351,13 @@ public class WebAppProxyServlet extends HttpServlet {
throw new IOException(e); throw new IOException(e);
} }
} }
private void readObject(ObjectInputStream input)
throws IOException, ClassNotFoundException {
input.defaultReadObject();
conf = new YarnConfiguration();
this.trackingUriPlugins =
conf.getInstances(YarnConfiguration.YARN_TRACKING_URL_GENERATOR,
TrackingUriPlugin.class);
}
} }