HADOOP-12940. Fix warnings from Spotbugs in hadoop-common.
This commit is contained in:
parent
8ceaac1877
commit
092ebdf885
@ -186,11 +186,12 @@ public AuthenticationToken authenticate(HttpServletRequest request,
|
|||||||
String authorization =
|
String authorization =
|
||||||
request.getHeader(HttpConstants.AUTHORIZATION_HEADER);
|
request.getHeader(HttpConstants.AUTHORIZATION_HEADER);
|
||||||
if (authorization != null) {
|
if (authorization != null) {
|
||||||
for (String scheme : schemeToAuthHandlerMapping.keySet()) {
|
for (Map.Entry<String, AuthenticationHandler> entry :
|
||||||
if (AuthenticationHandlerUtil.matchAuthScheme(scheme, authorization)) {
|
schemeToAuthHandlerMapping.entrySet()) {
|
||||||
AuthenticationHandler handler =
|
if (AuthenticationHandlerUtil.matchAuthScheme(
|
||||||
schemeToAuthHandlerMapping.get(scheme);
|
entry.getKey(), authorization)) {
|
||||||
AuthenticationToken token = handler.authenticate(request, response);
|
AuthenticationToken token =
|
||||||
|
entry.getValue().authenticate(request, response);
|
||||||
logger.trace("Token generated with type {}", token.getType());
|
logger.trace("Token generated with type {}", token.getType());
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
@ -416,4 +416,30 @@
|
|||||||
<Method name="toString"/>
|
<Method name="toString"/>
|
||||||
<Bug pattern="DM_DEFAULT_ENCODING"/>
|
<Bug pattern="DM_DEFAULT_ENCODING"/>
|
||||||
</Match>
|
</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>
|
</FindBugsFilter>
|
||||||
|
@ -115,8 +115,10 @@ public static void fullyDeleteOnExit(final File file) {
|
|||||||
file.deleteOnExit();
|
file.deleteOnExit();
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
File[] files = file.listFiles();
|
File[] files = file.listFiles();
|
||||||
for (File child : files) {
|
if (files != null) {
|
||||||
fullyDeleteOnExit(child);
|
for (File child : files) {
|
||||||
|
fullyDeleteOnExit(child);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -384,13 +384,16 @@ public final boolean handleEmptyDstDirectoryOnWindows(Path src, File srcFile,
|
|||||||
// again.
|
// again.
|
||||||
try {
|
try {
|
||||||
FileStatus sdst = this.getFileStatus(dst);
|
FileStatus sdst = this.getFileStatus(dst);
|
||||||
if (sdst.isDirectory() && dstFile.list().length == 0) {
|
String[] dstFileList = dstFile.list();
|
||||||
if (LOG.isDebugEnabled()) {
|
if (dstFileList != null) {
|
||||||
LOG.debug("Deleting empty destination and renaming " + src + " to " +
|
if (sdst.isDirectory() && dstFileList.length == 0) {
|
||||||
dst);
|
if (LOG.isDebugEnabled()) {
|
||||||
}
|
LOG.debug("Deleting empty destination and renaming " + src +
|
||||||
if (this.delete(dst, false) && srcFile.renameTo(dstFile)) {
|
" to " + dst);
|
||||||
return true;
|
}
|
||||||
|
if (this.delete(dst, false) && srcFile.renameTo(dstFile)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException ignored) {
|
} catch (FileNotFoundException ignored) {
|
||||||
|
@ -501,7 +501,7 @@ FSDataOutputStream create(PathData item, boolean lazyPersist,
|
|||||||
createFlags,
|
createFlags,
|
||||||
getConf().getInt(IO_FILE_BUFFER_SIZE_KEY,
|
getConf().getInt(IO_FILE_BUFFER_SIZE_KEY,
|
||||||
IO_FILE_BUFFER_SIZE_DEFAULT),
|
IO_FILE_BUFFER_SIZE_DEFAULT),
|
||||||
lazyPersist ? 1 : getDefaultReplication(item.path),
|
(short) 1,
|
||||||
getDefaultBlockSize(),
|
getDefaultBlockSize(),
|
||||||
null,
|
null,
|
||||||
null);
|
null);
|
||||||
|
@ -75,7 +75,7 @@ public int hashCode() {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(DoubleWritable o) {
|
public int compareTo(DoubleWritable o) {
|
||||||
return (value < o.value ? -1 : (value == o.value ? 0 : 1));
|
return Double.compare(value, o.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -94,7 +94,7 @@ public int compare(byte[] b1, int s1, int l1,
|
|||||||
byte[] b2, int s2, int l2) {
|
byte[] b2, int s2, int l2) {
|
||||||
double thisValue = readDouble(b1, s1);
|
double thisValue = readDouble(b1, s1);
|
||||||
double thatValue = readDouble(b2, s2);
|
double thatValue = readDouble(b2, s2);
|
||||||
return (thisValue < thatValue ? -1 : (thisValue == thatValue ? 0 : 1));
|
return Double.compare(thisValue, thatValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,9 +66,7 @@ public int hashCode() {
|
|||||||
/** Compares two FloatWritables. */
|
/** Compares two FloatWritables. */
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(FloatWritable o) {
|
public int compareTo(FloatWritable o) {
|
||||||
float thisValue = this.value;
|
return Float.compare(value, o.value);
|
||||||
float thatValue = o.value;
|
|
||||||
return (thisValue<thatValue ? -1 : (thisValue==thatValue ? 0 : 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -86,7 +84,7 @@ public int compare(byte[] b1, int s1, int l1,
|
|||||||
byte[] b2, int s2, int l2) {
|
byte[] b2, int s2, int l2) {
|
||||||
float thisValue = readFloat(b1, s1);
|
float thisValue = readFloat(b1, s1);
|
||||||
float thatValue = readFloat(b2, s2);
|
float thatValue = readFloat(b2, s2);
|
||||||
return (thisValue<thatValue ? -1 : (thisValue==thatValue ? 0 : 1));
|
return Float.compare(thisValue, thatValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,9 +371,12 @@ public static List<String> listDirectory(File dir, FilenameFilter filter)
|
|||||||
try (DirectoryStream<Path> stream =
|
try (DirectoryStream<Path> stream =
|
||||||
Files.newDirectoryStream(dir.toPath())) {
|
Files.newDirectoryStream(dir.toPath())) {
|
||||||
for (Path entry: stream) {
|
for (Path entry: stream) {
|
||||||
String fileName = entry.getFileName().toString();
|
Path fileName = entry.getFileName();
|
||||||
if ((filter == null) || filter.accept(dir, fileName)) {
|
if (fileName != null) {
|
||||||
list.add(fileName);
|
String fileNameStr = fileName.toString();
|
||||||
|
if ((filter == null) || filter.accept(dir, fileNameStr)) {
|
||||||
|
list.add(fileNameStr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (DirectoryIteratorException e) {
|
} catch (DirectoryIteratorException e) {
|
||||||
|
@ -189,8 +189,8 @@ public String toString() {
|
|||||||
sb.append((extraOptions.isEmpty() ? "" : ", "));
|
sb.append((extraOptions.isEmpty() ? "" : ", "));
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (String opt : extraOptions.keySet()) {
|
for (Map.Entry<String, String> entry : extraOptions.entrySet()) {
|
||||||
sb.append(opt + "=" + extraOptions.get(opt) +
|
sb.append(entry.getKey() + "=" + entry.getValue() +
|
||||||
(++i < extraOptions.size() ? ", " : ""));
|
(++i < extraOptions.size() ? ", " : ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,7 +395,7 @@ public boolean equals(Object other) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (major << 16 + minor);
|
return (major << 16) + minor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -881,11 +881,9 @@ private void addOrUpdateToken(TokenIdent ident,
|
|||||||
String nodeCreatePath =
|
String nodeCreatePath =
|
||||||
getNodePath(ZK_DTSM_TOKENS_ROOT, DELEGATION_TOKEN_PREFIX
|
getNodePath(ZK_DTSM_TOKENS_ROOT, DELEGATION_TOKEN_PREFIX
|
||||||
+ ident.getSequenceNumber());
|
+ 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);
|
ident.write(tokenOut);
|
||||||
tokenOut.writeLong(info.getRenewDate());
|
tokenOut.writeLong(info.getRenewDate());
|
||||||
tokenOut.writeInt(info.getPassword().length);
|
tokenOut.writeInt(info.getPassword().length);
|
||||||
@ -902,8 +900,6 @@ private void addOrUpdateToken(TokenIdent ident,
|
|||||||
zkClient.create().withMode(CreateMode.PERSISTENT)
|
zkClient.create().withMode(CreateMode.PERSISTENT)
|
||||||
.forPath(nodeCreatePath, tokenOs.toByteArray());
|
.forPath(nodeCreatePath, tokenOs.toByteArray());
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
seqOs.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ public long getAvailablePhysicalMemorySize() {
|
|||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public int getNumProcessors() {
|
public synchronized int getNumProcessors() {
|
||||||
refreshIfNeeded();
|
refreshIfNeeded();
|
||||||
return numProcessors;
|
return numProcessors;
|
||||||
}
|
}
|
||||||
@ -196,7 +196,7 @@ public long getCumulativeCpuTime() {
|
|||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public float getCpuUsagePercentage() {
|
public synchronized float getCpuUsagePercentage() {
|
||||||
refreshIfNeeded();
|
refreshIfNeeded();
|
||||||
float ret = cpuUsage;
|
float ret = cpuUsage;
|
||||||
if (ret != -1) {
|
if (ret != -1) {
|
||||||
@ -207,7 +207,7 @@ public float getCpuUsagePercentage() {
|
|||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public float getNumVCoresUsed() {
|
public synchronized float getNumVCoresUsed() {
|
||||||
refreshIfNeeded();
|
refreshIfNeeded();
|
||||||
float ret = cpuUsage;
|
float ret = cpuUsage;
|
||||||
if (ret != -1) {
|
if (ret != -1) {
|
||||||
|
@ -365,8 +365,11 @@ private void delete(File f) {
|
|||||||
LOG.warn("WARNING: cannot delete file " + f.getAbsolutePath());
|
LOG.warn("WARNING: cannot delete file " + f.getAbsolutePath());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (File c: f.listFiles()) {
|
File[] fileList = f.listFiles();
|
||||||
delete(c);
|
if (fileList != null) {
|
||||||
|
for (File c : fileList) {
|
||||||
|
delete(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (! f.delete()) {
|
if (! f.delete()) {
|
||||||
LOG.warn("WARNING: cannot delete directory " + f.getAbsolutePath());
|
LOG.warn("WARNING: cannot delete directory " + f.getAbsolutePath());
|
||||||
|
Loading…
Reference in New Issue
Block a user