From b76b843c8bd3906aaa5ad633d8a939aebc671907 Mon Sep 17 00:00:00 2001 From: Inigo Goiri Date: Mon, 24 Jun 2019 17:52:33 -0700 Subject: [PATCH] HDFS-13371. NPE for FsServerDefaults.getKeyProviderUri() for clientProtocol communication between 2.7 and 3.X. Contributed by Sherwood Zheng. --- .../apache/hadoop/hdfs/protocolPB/PBHelperClient.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelperClient.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelperClient.java index 829d3ef640a..b0eb99c8088 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelperClient.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelperClient.java @@ -2265,7 +2265,7 @@ public class PBHelperClient { public static FsServerDefaultsProto convert(FsServerDefaults fs) { if (fs == null) return null; - return FsServerDefaultsProto.newBuilder(). + FsServerDefaultsProto.Builder builder = FsServerDefaultsProto.newBuilder(). setBlockSize(fs.getBlockSize()). setBytesPerChecksum(fs.getBytesPerChecksum()). setWritePacketSize(fs.getWritePacketSize()) @@ -2274,9 +2274,11 @@ public class PBHelperClient { .setEncryptDataTransfer(fs.getEncryptDataTransfer()) .setTrashInterval(fs.getTrashInterval()) .setChecksumType(convert(fs.getChecksumType())) - .setKeyProviderUri(fs.getKeyProviderUri()) - .setPolicyId(fs.getDefaultStoragePolicyId()) - .build(); + .setPolicyId(fs.getDefaultStoragePolicyId()); + if (fs.getKeyProviderUri() != null) { + builder.setKeyProviderUri(fs.getKeyProviderUri()); + } + return builder.build(); } public static EnumSetWritable convertCreateFlag(int flag) {