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 2017/06/23 01:30:15 UTC
hadoop git commit: HADOOP-12940. Fix warnings from Spotbugs in
hadoop-common.
Repository: hadoop
Updated Branches:
refs/heads/trunk 8ceaac187 -> 092ebdf88
HADOOP-12940. Fix warnings from Spotbugs in hadoop-common.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/092ebdf8
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/092ebdf8
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/092ebdf8
Branch: refs/heads/trunk
Commit: 092ebdf885468a2bf79cbfb168286b7cddc4a0db
Parents: 8ceaac1
Author: Akira Ajisaka <aa...@apache.org>
Authored: Fri Jun 23 10:28:58 2017 +0900
Committer: Akira Ajisaka <aa...@apache.org>
Committed: Fri Jun 23 10:28:58 2017 +0900
----------------------------------------------------------------------
.../MultiSchemeAuthenticationHandler.java | 11 +++++----
.../dev-support/findbugsExcludeFile.xml | 26 ++++++++++++++++++++
.../java/org/apache/hadoop/fs/FileUtil.java | 6 +++--
.../apache/hadoop/fs/RawLocalFileSystem.java | 17 +++++++------
.../hadoop/fs/shell/CommandWithDestination.java | 2 +-
.../org/apache/hadoop/io/DoubleWritable.java | 4 +--
.../org/apache/hadoop/io/FloatWritable.java | 6 ++---
.../main/java/org/apache/hadoop/io/IOUtils.java | 9 ++++---
.../apache/hadoop/io/erasurecode/ECSchema.java | 4 +--
.../org/apache/hadoop/io/file/tfile/Utils.java | 2 +-
.../ZKDelegationTokenSecretManager.java | 8 ++----
.../org/apache/hadoop/util/SysInfoWindows.java | 6 ++---
.../java/org/apache/hadoop/minikdc/MiniKdc.java | 7 ++++--
13 files changed, 70 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/092ebdf8/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/MultiSchemeAuthenticationHandler.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/MultiSchemeAuthenticationHandler.java b/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/MultiSchemeAuthenticationHandler.java
index aa49100..58a0adb 100644
--- a/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/MultiSchemeAuthenticationHandler.java
+++ b/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/MultiSchemeAuthenticationHandler.java
@@ -186,11 +186,12 @@ public class MultiSchemeAuthenticationHandler implements
String authorization =
request.getHeader(HttpConstants.AUTHORIZATION_HEADER);
if (authorization != null) {
- for (String scheme : schemeToAuthHandlerMapping.keySet()) {
- if (AuthenticationHandlerUtil.matchAuthScheme(scheme, authorization)) {
- AuthenticationHandler handler =
- schemeToAuthHandlerMapping.get(scheme);
- AuthenticationToken token = handler.authenticate(request, response);
+ for (Map.Entry<String, AuthenticationHandler> entry :
+ schemeToAuthHandlerMapping.entrySet()) {
+ if (AuthenticationHandlerUtil.matchAuthScheme(
+ entry.getKey(), authorization)) {
+ AuthenticationToken token =
+ entry.getValue().authenticate(request, response);
logger.trace("Token generated with type {}", token.getType());
return token;
}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/092ebdf8/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml b/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml
index cdd88f3..de76afb 100644
--- a/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml
+++ b/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml
@@ -416,4 +416,30 @@
<Method name="toString"/>
<Bug pattern="DM_DEFAULT_ENCODING"/>
</Match>
+
+ <!-- We need to make the methods public because PBHelperClient calls them. -->
+ <Match>
+ <Class name="org.apache.hadoop.crypto.CipherSuite"/>
+ <Method name="setUnknownValue"/>
+ <Bug pattern="ME_ENUM_FIELD_SETTER"/>
+ </Match>
+ <Match>
+ <Class name="org.apache.hadoop.crypto.CryptoProtocolVersion"/>
+ <Method name="setUnknownValue"/>
+ <Bug pattern="ME_ENUM_FIELD_SETTER"/>
+ </Match>
+
+ <!-- We need to make the method public for testing. -->
+ <Match>
+ <Class name="org.apache.hadoop.metrics2.lib.DefaultMetricsSystem"/>
+ <Method name="setMiniClusterMode"/>
+ <Bug pattern="ME_ENUM_FIELD_SETTER"/>
+ </Match>
+
+ <!-- Experimental interface. Ignore. -->
+ <Match>
+ <Class name="org.apache.hadoop.metrics2.lib.DefaultMetricsFactory"/>
+ <Method name="setInstance"/>
+ <Bug pattern="ME_ENUM_FIELD_SETTER"/>
+ </Match>
</FindBugsFilter>
http://git-wip-us.apache.org/repos/asf/hadoop/blob/092ebdf8/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
index 0b27a7e..b656a87 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
@@ -115,8 +115,10 @@ public class FileUtil {
file.deleteOnExit();
if (file.isDirectory()) {
File[] files = file.listFiles();
- for (File child : files) {
- fullyDeleteOnExit(child);
+ if (files != null) {
+ for (File child : files) {
+ fullyDeleteOnExit(child);
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/092ebdf8/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
index e4e0659..721d0c0 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
@@ -384,13 +384,16 @@ public class RawLocalFileSystem extends FileSystem {
// again.
try {
FileStatus sdst = this.getFileStatus(dst);
- if (sdst.isDirectory() && dstFile.list().length == 0) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Deleting empty destination and renaming " + src + " to " +
- dst);
- }
- if (this.delete(dst, false) && srcFile.renameTo(dstFile)) {
- return true;
+ String[] dstFileList = dstFile.list();
+ if (dstFileList != null) {
+ if (sdst.isDirectory() && dstFileList.length == 0) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Deleting empty destination and renaming " + src +
+ " to " + dst);
+ }
+ if (this.delete(dst, false) && srcFile.renameTo(dstFile)) {
+ return true;
+ }
}
}
} catch (FileNotFoundException ignored) {
http://git-wip-us.apache.org/repos/asf/hadoop/blob/092ebdf8/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java
index 578d22b..2a483c0 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java
@@ -501,7 +501,7 @@ abstract class CommandWithDestination extends FsCommand {
createFlags,
getConf().getInt(IO_FILE_BUFFER_SIZE_KEY,
IO_FILE_BUFFER_SIZE_DEFAULT),
- lazyPersist ? 1 : getDefaultReplication(item.path),
+ (short) 1,
getDefaultBlockSize(),
null,
null);
http://git-wip-us.apache.org/repos/asf/hadoop/blob/092ebdf8/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DoubleWritable.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DoubleWritable.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DoubleWritable.java
index 5cc326f..f45ed0a 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DoubleWritable.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DoubleWritable.java
@@ -75,7 +75,7 @@ public class DoubleWritable implements WritableComparable<DoubleWritable> {
@Override
public int compareTo(DoubleWritable o) {
- return (value < o.value ? -1 : (value == o.value ? 0 : 1));
+ return Double.compare(value, o.value);
}
@Override
@@ -94,7 +94,7 @@ public class DoubleWritable implements WritableComparable<DoubleWritable> {
byte[] b2, int s2, int l2) {
double thisValue = readDouble(b1, s1);
double thatValue = readDouble(b2, s2);
- return (thisValue < thatValue ? -1 : (thisValue == thatValue ? 0 : 1));
+ return Double.compare(thisValue, thatValue);
}
}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/092ebdf8/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/FloatWritable.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/FloatWritable.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/FloatWritable.java
index 21e4cc4..367fc94 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/FloatWritable.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/FloatWritable.java
@@ -66,9 +66,7 @@ public class FloatWritable implements WritableComparable<FloatWritable> {
/** Compares two FloatWritables. */
@Override
public int compareTo(FloatWritable o) {
- float thisValue = this.value;
- float thatValue = o.value;
- return (thisValue<thatValue ? -1 : (thisValue==thatValue ? 0 : 1));
+ return Float.compare(value, o.value);
}
@Override
@@ -86,7 +84,7 @@ public class FloatWritable implements WritableComparable<FloatWritable> {
byte[] b2, int s2, int l2) {
float thisValue = readFloat(b1, s1);
float thatValue = readFloat(b2, s2);
- return (thisValue<thatValue ? -1 : (thisValue==thatValue ? 0 : 1));
+ return Float.compare(thisValue, thatValue);
}
}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/092ebdf8/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java
index 459014b..e24f196 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java
@@ -371,9 +371,12 @@ public class IOUtils {
try (DirectoryStream<Path> stream =
Files.newDirectoryStream(dir.toPath())) {
for (Path entry: stream) {
- String fileName = entry.getFileName().toString();
- if ((filter == null) || filter.accept(dir, fileName)) {
- list.add(fileName);
+ Path fileName = entry.getFileName();
+ if (fileName != null) {
+ String fileNameStr = fileName.toString();
+ if ((filter == null) || filter.accept(dir, fileNameStr)) {
+ list.add(fileNameStr);
+ }
}
}
} catch (DirectoryIteratorException e) {
http://git-wip-us.apache.org/repos/asf/hadoop/blob/092ebdf8/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/ECSchema.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/ECSchema.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/ECSchema.java
index e55fbdd..4d66019 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/ECSchema.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/ECSchema.java
@@ -189,8 +189,8 @@ public final class ECSchema {
sb.append((extraOptions.isEmpty() ? "" : ", "));
int i = 0;
- for (String opt : extraOptions.keySet()) {
- sb.append(opt + "=" + extraOptions.get(opt) +
+ for (Map.Entry<String, String> entry : extraOptions.entrySet()) {
+ sb.append(entry.getKey() + "=" + entry.getValue() +
(++i < extraOptions.size() ? ", " : ""));
}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/092ebdf8/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/file/tfile/Utils.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/file/tfile/Utils.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/file/tfile/Utils.java
index 5743c66..8cb6e0d 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/file/tfile/Utils.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/file/tfile/Utils.java
@@ -395,7 +395,7 @@ public final class Utils {
@Override
public int hashCode() {
- return (major << 16 + minor);
+ return (major << 16) + minor;
}
}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/092ebdf8/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java
index 4a7ddb2..88bd29b 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java
@@ -881,11 +881,9 @@ public abstract class ZKDelegationTokenSecretManager<TokenIdent extends Abstract
String nodeCreatePath =
getNodePath(ZK_DTSM_TOKENS_ROOT, DELEGATION_TOKEN_PREFIX
+ ident.getSequenceNumber());
- ByteArrayOutputStream tokenOs = new ByteArrayOutputStream();
- DataOutputStream tokenOut = new DataOutputStream(tokenOs);
- ByteArrayOutputStream seqOs = new ByteArrayOutputStream();
- try {
+ try (ByteArrayOutputStream tokenOs = new ByteArrayOutputStream();
+ DataOutputStream tokenOut = new DataOutputStream(tokenOs)) {
ident.write(tokenOut);
tokenOut.writeLong(info.getRenewDate());
tokenOut.writeInt(info.getPassword().length);
@@ -902,8 +900,6 @@ public abstract class ZKDelegationTokenSecretManager<TokenIdent extends Abstract
zkClient.create().withMode(CreateMode.PERSISTENT)
.forPath(nodeCreatePath, tokenOs.toByteArray());
}
- } finally {
- seqOs.close();
}
}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/092ebdf8/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/SysInfoWindows.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/SysInfoWindows.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/SysInfoWindows.java
index 8b4ea54..bce2d6d 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/SysInfoWindows.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/SysInfoWindows.java
@@ -169,7 +169,7 @@ public class SysInfoWindows extends SysInfo {
/** {@inheritDoc} */
@Override
- public int getNumProcessors() {
+ public synchronized int getNumProcessors() {
refreshIfNeeded();
return numProcessors;
}
@@ -196,7 +196,7 @@ public class SysInfoWindows extends SysInfo {
/** {@inheritDoc} */
@Override
- public float getCpuUsagePercentage() {
+ public synchronized float getCpuUsagePercentage() {
refreshIfNeeded();
float ret = cpuUsage;
if (ret != -1) {
@@ -207,7 +207,7 @@ public class SysInfoWindows extends SysInfo {
/** {@inheritDoc} */
@Override
- public float getNumVCoresUsed() {
+ public synchronized float getNumVCoresUsed() {
refreshIfNeeded();
float ret = cpuUsage;
if (ret != -1) {
http://git-wip-us.apache.org/repos/asf/hadoop/blob/092ebdf8/hadoop-common-project/hadoop-minikdc/src/main/java/org/apache/hadoop/minikdc/MiniKdc.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-minikdc/src/main/java/org/apache/hadoop/minikdc/MiniKdc.java b/hadoop-common-project/hadoop-minikdc/src/main/java/org/apache/hadoop/minikdc/MiniKdc.java
index fe194c0..6f91018 100644
--- a/hadoop-common-project/hadoop-minikdc/src/main/java/org/apache/hadoop/minikdc/MiniKdc.java
+++ b/hadoop-common-project/hadoop-minikdc/src/main/java/org/apache/hadoop/minikdc/MiniKdc.java
@@ -365,8 +365,11 @@ public class MiniKdc {
LOG.warn("WARNING: cannot delete file " + f.getAbsolutePath());
}
} else {
- for (File c: f.listFiles()) {
- delete(c);
+ File[] fileList = f.listFiles();
+ if (fileList != null) {
+ for (File c : fileList) {
+ delete(c);
+ }
}
if (! f.delete()) {
LOG.warn("WARNING: cannot delete directory " + f.getAbsolutePath());
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org