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
This commit is contained in:
Yi Liu 2014-08-06 04:43:58 +00:00
parent ac47ad11de
commit 2b5e044424
4 changed files with 17 additions and 19 deletions

View File

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

View File

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

View File

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

View File

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