You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by yq...@apache.org on 2019/02/08 12:52:04 UTC

[hadoop] branch trunk updated: HDFS-14172. Avoid NPE when SectionName#fromString returns null. Contributed by Xiang Li.

This is an automated email from the ASF dual-hosted git repository.

yqlin pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 1771317  HDFS-14172. Avoid NPE when SectionName#fromString returns null. Contributed by Xiang Li.
1771317 is described below

commit 177131793a88960b734038f6e646476d568c3626
Author: Yiqun Lin <yq...@apache.org>
AuthorDate: Fri Feb 8 20:51:30 2019 +0800

    HDFS-14172. Avoid NPE when SectionName#fromString returns null. Contributed by Xiang Li.
---
 .../apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java | 7 +++++--
 .../hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java       | 8 +++++++-
 .../hadoop/hdfs/tools/offlineImageViewer/PBImageTextWriter.java   | 6 +++++-
 .../hadoop/hdfs/tools/offlineImageViewer/PBImageXmlWriter.java    | 6 +++++-
 4 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
index 7aed5fd..ad883b1 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
@@ -241,8 +241,11 @@ public final class FSImageFormatProtobuf {
             summary.getCodec(), in);
 
         String n = s.getName();
-
-        switch (SectionName.fromString(n)) {
+        SectionName sectionName = SectionName.fromString(n);
+        if (sectionName == null) {
+          throw new IOException("Unrecognized section " + n);
+        }
+        switch (sectionName) {
         case NS_INFO:
           loadNameSystemSection(in);
           break;
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java
index 7152c88..f65d29c 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java
@@ -156,7 +156,13 @@ class FSImageLoader {
           LOG.debug("Loading section " + s.getName() + " length: " + s.getLength
               ());
         }
-        switch (FSImageFormatProtobuf.SectionName.fromString(s.getName())) {
+
+        FSImageFormatProtobuf.SectionName sectionName
+            = FSImageFormatProtobuf.SectionName.fromString(s.getName());
+        if (sectionName == null) {
+          throw new IOException("Unrecognized section " + s.getName());
+        }
+        switch (sectionName) {
           case STRING_TABLE:
             stringTable = loadStringTable(is);
             break;
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageTextWriter.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageTextWriter.java
index 6f36be4..c5bf5af 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageTextWriter.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageTextWriter.java
@@ -594,7 +594,11 @@ abstract class PBImageTextWriter implements Closeable {
         is = FSImageUtil.wrapInputStreamForCompression(conf,
             summary.getCodec(), new BufferedInputStream(new LimitInputStream(
                 fin, section.getLength())));
-        switch (SectionName.fromString(section.getName())) {
+        SectionName sectionName = SectionName.fromString(section.getName());
+        if (sectionName == null) {
+          throw new IOException("Unrecognized section " + section.getName());
+        }
+        switch (sectionName) {
         case STRING_TABLE:
           LOG.info("Loading string table");
           stringTable = FSImageLoader.loadStringTable(is);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageXmlWriter.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageXmlWriter.java
index 7a5ef31..cec44f5 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageXmlWriter.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageXmlWriter.java
@@ -326,7 +326,11 @@ public final class PBImageXmlWriter {
             summary.getCodec(), new BufferedInputStream(new LimitInputStream(
                 fin, s.getLength())));
 
-        switch (SectionName.fromString(s.getName())) {
+        SectionName sectionName = SectionName.fromString(s.getName());
+        if (sectionName == null) {
+          throw new IOException("Unrecognized section " + s.getName());
+        }
+        switch (sectionName) {
         case NS_INFO:
           dumpNameSection(is);
           break;


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org