Explorar o código

HDFS-6817. Fix findbugs and other warnings. (yliu)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/fs-encryption@1616092 13f79535-47bb-0310-9956-ffa450edef68
Yi Liu %!s(int64=10) %!d(string=hai) anos
pai
achega
2b5e044424

+ 4 - 8
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/AesCtrCryptoCodec.java

@@ -50,14 +50,10 @@ public abstract class AesCtrCryptoCodec extends CryptoCodec {
     Preconditions.checkArgument(IV.length == AES_BLOCK_SIZE);
     
     System.arraycopy(initIV, 0, IV, 0, CTR_OFFSET);
-    long l = (initIV[CTR_OFFSET + 0] << 56)
-        + ((initIV[CTR_OFFSET + 1] & 0xFF) << 48)
-        + ((initIV[CTR_OFFSET + 2] & 0xFF) << 40)
-        + ((initIV[CTR_OFFSET + 3] & 0xFF) << 32)
-        + ((initIV[CTR_OFFSET + 4] & 0xFF) << 24)
-        + ((initIV[CTR_OFFSET + 5] & 0xFF) << 16)
-        + ((initIV[CTR_OFFSET + 6] & 0xFF) << 8)
-        + (initIV[CTR_OFFSET + 7] & 0xFF);
+    long l = 0;
+    for (int i = 0; i < 8; i++) {
+      l = ((l << 8) | (initIV[CTR_OFFSET + i] & 0xff));
+    }
     l += counter;
     IV[CTR_OFFSET + 0] = (byte) (l >>> 56);
     IV[CTR_OFFSET + 1] = (byte) (l >>> 48);

+ 10 - 10
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/random/OsSecureRandom.java

@@ -37,14 +37,15 @@ import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY
  */
 @InterfaceAudience.Private
 public class OsSecureRandom extends Random implements Closeable, Configurable {
+  private static final long serialVersionUID = 6391500337172057900L;
 
-  private Configuration conf;
+  private transient Configuration conf;
 
   private final int RESERVOIR_LENGTH = 8192;
 
   private String randomDevPath;
 
-  private FileInputStream stream;
+  private transient FileInputStream stream;
 
   private final byte[] reservoir = new byte[RESERVOIR_LENGTH];
 
@@ -65,7 +66,7 @@ public class OsSecureRandom extends Random implements Closeable, Configurable {
   }
   
   @Override
-  public void setConf(Configuration conf) {
+  synchronized public void setConf(Configuration conf) {
     this.conf = conf;
     this.randomDevPath = conf.get(
         HADOOP_SECURITY_SECURE_RANDOM_DEVICE_FILE_PATH_KEY,
@@ -80,7 +81,7 @@ public class OsSecureRandom extends Random implements Closeable, Configurable {
   }
 
   @Override
-  public Configuration getConf() {
+  synchronized public Configuration getConf() {
     return conf;
   }
 
@@ -100,16 +101,15 @@ public class OsSecureRandom extends Random implements Closeable, Configurable {
   @Override
   synchronized protected int next(int nbits) {
     fillReservoir(4);
-    int n = reservoir[pos] |
-        (reservoir[pos + 1] << 8) |
-        (reservoir[pos + 2] << 16) |
-        (reservoir[pos + 3] << 24);
-    pos += 4;
+    int n = 0;
+    for (int i = 0; i < 4; i++) {
+      n = ((n << 8) | (reservoir[pos++] & 0xff));
+    }
     return n & (0xffffffff >> (32 - nbits));
   }
 
   @Override
-  public void close() throws IOException {
+  synchronized public void close() throws IOException {
     stream.close();
   }
 }

+ 2 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES-fs-encryption.txt

@@ -90,3 +90,5 @@ fs-encryption (Unreleased)
 
     HDFS-6814. Mistakenly dfs.namenode.list.encryption.zones.num.responses configured
     as boolean. (umamahesh)
+
+    HDFS-6817. Fix findbugs and other warnings. (yliu)

+ 1 - 1
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java

@@ -41,7 +41,7 @@ public class EncryptionZoneManager {
    * external representation of an EZ is embodied in an EncryptionZone and
    * contains the EZ's pathname.
    */
-  private class EncryptionZoneInt {
+  private static class EncryptionZoneInt {
     private final String keyName;
     private final long inodeId;