diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/mount/MountResponse.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/mount/MountResponse.java index 5e101c1de8..889d45a444 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/mount/MountResponse.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/mount/MountResponse.java @@ -19,6 +19,7 @@ import java.util.List; +import org.apache.commons.io.Charsets; import org.apache.hadoop.nfs.NfsExports; import org.apache.hadoop.oncrpc.RpcAcceptedReply; import org.apache.hadoop.oncrpc.XDR; @@ -76,7 +77,7 @@ public static XDR writeExportList(XDR xdr, int xid, List exports, if (hostGroups.length > 0) { for (int j = 0; j < hostGroups.length; j++) { xdr.writeBoolean(true); // Value follows - yes - xdr.writeVariableOpaque(hostGroups[j].getBytes()); + xdr.writeVariableOpaque(hostGroups[j].getBytes(Charsets.UTF_8)); } } xdr.writeBoolean(false); // Value follows - no more group diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/FileHandle.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/FileHandle.java index 6bc4686157..415b459f68 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/FileHandle.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/FileHandle.java @@ -22,6 +22,7 @@ import java.security.NoSuchAlgorithmException; import java.util.Arrays; +import org.apache.commons.io.Charsets; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.oncrpc.XDR; @@ -72,10 +73,8 @@ public FileHandle(String s) { return; } - byte[] in = s.getBytes(); - for (int i = 0; i < in.length; i++) { - digest.update(in[i]); - } + byte[] in = s.getBytes(Charsets.UTF_8); + digest.update(in); byte[] digestbytes = digest.digest(); for (int i = 0; i < 16; i++) { diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/CREATE3Request.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/CREATE3Request.java index 473d527646..e75ce15b52 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/CREATE3Request.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/CREATE3Request.java @@ -19,6 +19,7 @@ import java.io.IOException; +import org.apache.commons.io.Charsets; import org.apache.hadoop.nfs.nfs3.FileHandle; import org.apache.hadoop.nfs.nfs3.Nfs3Constant; import org.apache.hadoop.oncrpc.XDR; @@ -78,7 +79,7 @@ public long getVerf() { public void serialize(XDR xdr) { handle.serialize(xdr); xdr.writeInt(name.length()); - xdr.writeFixedOpaque(name.getBytes(), name.length()); + xdr.writeFixedOpaque(name.getBytes(Charsets.UTF_8), name.length()); xdr.writeInt(mode); objAttr.serialize(xdr); } diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/LINK3Request.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/LINK3Request.java index 2e959f59f9..1dcb85d3d4 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/LINK3Request.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/LINK3Request.java @@ -19,6 +19,7 @@ import java.io.IOException; +import org.apache.commons.io.Charsets; import org.apache.hadoop.nfs.nfs3.FileHandle; import org.apache.hadoop.oncrpc.XDR; @@ -56,6 +57,6 @@ public void serialize(XDR xdr) { handle.serialize(xdr); fromDirHandle.serialize(xdr); xdr.writeInt(fromName.length()); - xdr.writeFixedOpaque(fromName.getBytes(), fromName.length()); + xdr.writeFixedOpaque(fromName.getBytes(Charsets.UTF_8), fromName.length()); } } diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/LOOKUP3Request.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/LOOKUP3Request.java index 4661821a68..0435483e83 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/LOOKUP3Request.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/LOOKUP3Request.java @@ -19,6 +19,7 @@ import java.io.IOException; +import org.apache.commons.io.Charsets; import org.apache.hadoop.nfs.nfs3.FileHandle; import org.apache.hadoop.oncrpc.XDR; @@ -53,7 +54,7 @@ public void setName(String name) { @VisibleForTesting public void serialize(XDR xdr) { handle.serialize(xdr); - xdr.writeInt(name.getBytes().length); - xdr.writeFixedOpaque(name.getBytes()); + xdr.writeInt(name.getBytes(Charsets.UTF_8).length); + xdr.writeFixedOpaque(name.getBytes(Charsets.UTF_8)); } } \ No newline at end of file diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/MKDIR3Request.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/MKDIR3Request.java index b3ef828a7e..bba26eeb30 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/MKDIR3Request.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/MKDIR3Request.java @@ -19,6 +19,7 @@ import java.io.IOException; +import org.apache.commons.io.Charsets; import org.apache.hadoop.nfs.nfs3.FileHandle; import org.apache.hadoop.oncrpc.XDR; @@ -54,8 +55,8 @@ public SetAttr3 getObjAttr() { @Override public void serialize(XDR xdr) { handle.serialize(xdr); - xdr.writeInt(name.getBytes().length); - xdr.writeFixedOpaque(name.getBytes()); + xdr.writeInt(name.getBytes(Charsets.UTF_8).length); + xdr.writeFixedOpaque(name.getBytes(Charsets.UTF_8)); objAttr.serialize(xdr); } } \ No newline at end of file diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/MKNOD3Request.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/MKNOD3Request.java index 4a13f879ea..0659dd10c0 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/MKNOD3Request.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/MKNOD3Request.java @@ -19,6 +19,7 @@ import java.io.IOException; +import org.apache.commons.io.Charsets; import org.apache.hadoop.nfs.NfsFileType; import org.apache.hadoop.nfs.nfs3.FileHandle; import org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes.Specdata3; @@ -79,7 +80,7 @@ public Specdata3 getSpec() { public void serialize(XDR xdr) { handle.serialize(xdr); xdr.writeInt(name.length()); - xdr.writeFixedOpaque(name.getBytes(), name.length()); + xdr.writeFixedOpaque(name.getBytes(Charsets.UTF_8), name.length()); objAttr.serialize(xdr); if (spec != null) { xdr.writeInt(spec.getSpecdata1()); diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/REMOVE3Request.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/REMOVE3Request.java index ffd47b0e5d..9ad156d90e 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/REMOVE3Request.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/REMOVE3Request.java @@ -19,6 +19,7 @@ import java.io.IOException; +import org.apache.commons.io.Charsets; import org.apache.hadoop.nfs.nfs3.FileHandle; import org.apache.hadoop.oncrpc.XDR; @@ -46,7 +47,7 @@ public String getName() { @Override public void serialize(XDR xdr) { handle.serialize(xdr); - xdr.writeInt(name.getBytes().length); - xdr.writeFixedOpaque(name.getBytes()); + xdr.writeInt(name.getBytes(Charsets.UTF_8).length); + xdr.writeFixedOpaque(name.getBytes(Charsets.UTF_8)); } } \ No newline at end of file diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/RENAME3Request.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/RENAME3Request.java index 5144e8a491..c54a8e2da2 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/RENAME3Request.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/RENAME3Request.java @@ -19,6 +19,7 @@ import java.io.IOException; +import org.apache.commons.io.Charsets; import org.apache.hadoop.nfs.nfs3.FileHandle; import org.apache.hadoop.oncrpc.XDR; @@ -66,10 +67,10 @@ public String getToName() { @Override public void serialize(XDR xdr) { fromDirHandle.serialize(xdr); - xdr.writeInt(fromName.getBytes().length); - xdr.writeFixedOpaque(fromName.getBytes()); + xdr.writeInt(fromName.getBytes(Charsets.UTF_8).length); + xdr.writeFixedOpaque(fromName.getBytes(Charsets.UTF_8)); toDirHandle.serialize(xdr); - xdr.writeInt(toName.getBytes().length); - xdr.writeFixedOpaque(toName.getBytes()); + xdr.writeInt(toName.getBytes(Charsets.UTF_8).length); + xdr.writeFixedOpaque(toName.getBytes(Charsets.UTF_8)); } } \ No newline at end of file diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/RMDIR3Request.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/RMDIR3Request.java index e9977fa548..6ae0de89fb 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/RMDIR3Request.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/RMDIR3Request.java @@ -19,6 +19,7 @@ import java.io.IOException; +import org.apache.commons.io.Charsets; import org.apache.hadoop.nfs.nfs3.FileHandle; import org.apache.hadoop.oncrpc.XDR; @@ -46,7 +47,7 @@ public String getName() { @Override public void serialize(XDR xdr) { handle.serialize(xdr); - xdr.writeInt(name.getBytes().length); - xdr.writeFixedOpaque(name.getBytes()); + xdr.writeInt(name.getBytes(Charsets.UTF_8).length); + xdr.writeFixedOpaque(name.getBytes(Charsets.UTF_8)); } } \ No newline at end of file diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/SYMLINK3Request.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/SYMLINK3Request.java index 288079449d..59188e2b50 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/SYMLINK3Request.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/request/SYMLINK3Request.java @@ -19,6 +19,7 @@ import java.io.IOException; +import org.apache.commons.io.Charsets; import org.apache.hadoop.nfs.nfs3.FileHandle; import org.apache.hadoop.oncrpc.XDR; @@ -62,10 +63,10 @@ public String getSymData() { @Override public void serialize(XDR xdr) { handle.serialize(xdr); - xdr.writeInt(name.getBytes().length); - xdr.writeFixedOpaque(name.getBytes()); + xdr.writeInt(name.getBytes(Charsets.UTF_8).length); + xdr.writeFixedOpaque(name.getBytes(Charsets.UTF_8)); symAttr.serialize(xdr); - xdr.writeInt(symData.getBytes().length); - xdr.writeFixedOpaque(symData.getBytes()); + xdr.writeInt(symData.getBytes(Charsets.UTF_8).length); + xdr.writeFixedOpaque(symData.getBytes(Charsets.UTF_8)); } } \ No newline at end of file diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/XDR.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/XDR.java index 2fdabe2fda..474559ea92 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/XDR.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/XDR.java @@ -19,6 +19,7 @@ import java.nio.ByteBuffer; +import org.apache.commons.io.Charsets; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; @@ -165,11 +166,11 @@ public void writeVariableOpaque(byte[] src) { } public String readString() { - return new String(readVariableOpaque()); + return new String(readVariableOpaque(), Charsets.UTF_8); } public void writeString(String s) { - writeVariableOpaque(s.getBytes()); + writeVariableOpaque(s.getBytes(Charsets.UTF_8)); } private void writePadding() { diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/CredentialsSys.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/CredentialsSys.java index 997ce35c60..d13c3615b2 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/CredentialsSys.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/CredentialsSys.java @@ -20,6 +20,7 @@ import java.net.InetAddress; import java.net.UnknownHostException; +import org.apache.commons.io.Charsets; import org.apache.hadoop.oncrpc.XDR; /** Credential used by AUTH_SYS */ @@ -93,7 +94,7 @@ public void read(XDR xdr) { @Override public void write(XDR xdr) { // mStamp + mHostName.length + mHostName + mUID + mGID + mAuxGIDs.count - mCredentialsLength = 20 + mHostName.getBytes().length; + mCredentialsLength = 20 + mHostName.getBytes(Charsets.UTF_8).length; // mAuxGIDs if (mAuxGIDs != null && mAuxGIDs.length > 0) { mCredentialsLength += mAuxGIDs.length * 4; diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 0ba4e075e9..ceb28ece9e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -592,6 +592,8 @@ Release 2.7.0 - UNRELEASED HDFS-7506. Consolidate implementation of setting inode attributes into a single class. (wheat9) + + HDFS-7516. Fix findbugs warnings in hdfs-nfs project. (brandonli) Release 2.6.1 - UNRELEASED