HDFS-7502. Fix findbugs warning in hdfs-nfs project. Contributed by Brandon Li.

This commit is contained in:
Haohui Mai 2014-12-09 20:42:42 -08:00
parent d93f3b9815
commit 195f31a8ef
2 changed files with 12 additions and 6 deletions

View File

@ -25,6 +25,7 @@
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.EnumSet; import java.util.EnumSet;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -651,15 +652,16 @@ READLINK3Response readlink(XDR xdr, SecurityHandler securityHandler,
} }
int rtmax = config.getInt(NfsConfigKeys.DFS_NFS_MAX_READ_TRANSFER_SIZE_KEY, int rtmax = config.getInt(NfsConfigKeys.DFS_NFS_MAX_READ_TRANSFER_SIZE_KEY,
NfsConfigKeys.DFS_NFS_MAX_READ_TRANSFER_SIZE_DEFAULT); NfsConfigKeys.DFS_NFS_MAX_READ_TRANSFER_SIZE_DEFAULT);
if (rtmax < target.getBytes().length) { if (rtmax < target.getBytes(Charset.forName("UTF-8")).length) {
LOG.error("Link size: " + target.getBytes().length LOG.error("Link size: "
+ target.getBytes(Charset.forName("UTF-8")).length
+ " is larger than max transfer size: " + rtmax); + " is larger than max transfer size: " + rtmax);
return new READLINK3Response(Nfs3Status.NFS3ERR_IO, postOpAttr, return new READLINK3Response(Nfs3Status.NFS3ERR_IO, postOpAttr,
new byte[0]); new byte[0]);
} }
return new READLINK3Response(Nfs3Status.NFS3_OK, postOpAttr, return new READLINK3Response(Nfs3Status.NFS3_OK, postOpAttr,
target.getBytes()); target.getBytes(Charset.forName("UTF-8")));
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Readlink error: " + e.getClass(), e); LOG.warn("Readlink error: " + e.getClass(), e);
@ -1462,7 +1464,8 @@ private DirectoryListing listPaths(DFSClient dfsClient, String dirFileIdPath,
throw io; throw io;
} }
// This happens when startAfter was just deleted // This happens when startAfter was just deleted
LOG.info("Cookie couldn't be found: " + new String(startAfter) LOG.info("Cookie couldn't be found: "
+ new String(startAfter, Charset.forName("UTF-8"))
+ ", do listing from beginning"); + ", do listing from beginning");
dlisting = dfsClient dlisting = dfsClient
.listPaths(dirFileIdPath, HdfsFileStatus.EMPTY_NAME); .listPaths(dirFileIdPath, HdfsFileStatus.EMPTY_NAME);
@ -1571,7 +1574,7 @@ public READDIR3Response readdir(XDR xdr, SecurityHandler securityHandler,
startAfter = HdfsFileStatus.EMPTY_NAME; startAfter = HdfsFileStatus.EMPTY_NAME;
} else { } else {
String inodeIdPath = Nfs3Utils.getFileIdPath(cookie); String inodeIdPath = Nfs3Utils.getFileIdPath(cookie);
startAfter = inodeIdPath.getBytes(); startAfter = inodeIdPath.getBytes(Charset.forName("UTF-8"));
} }
dlisting = listPaths(dfsClient, dirFileIdPath, startAfter); dlisting = listPaths(dfsClient, dirFileIdPath, startAfter);
@ -1733,7 +1736,7 @@ READDIRPLUS3Response readdirplus(XDR xdr, SecurityHandler securityHandler,
startAfter = HdfsFileStatus.EMPTY_NAME; startAfter = HdfsFileStatus.EMPTY_NAME;
} else { } else {
String inodeIdPath = Nfs3Utils.getFileIdPath(cookie); String inodeIdPath = Nfs3Utils.getFileIdPath(cookie);
startAfter = inodeIdPath.getBytes(); startAfter = inodeIdPath.getBytes(Charset.forName("UTF-8"));
} }
dlisting = listPaths(dfsClient, dirFileIdPath, startAfter); dlisting = listPaths(dfsClient, dirFileIdPath, startAfter);

View File

@ -561,6 +561,9 @@ Release 2.7.0 - UNRELEASED
HDFS-7481. Add ACL indicator to the "Permission Denied" exception. HDFS-7481. Add ACL indicator to the "Permission Denied" exception.
(vinayakumarb) (vinayakumarb)
HDFS-7502. Fix findbugs warning in hdfs-nfs project.
(Brandon Li via wheat9)
Release 2.6.1 - UNRELEASED Release 2.6.1 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES