[ https://issues.apache.org/jira/browse/HDFS-14172?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16757034#comment-16757034 ]
Xiang Li edited comment on HDFS-14172 at 1/31/19 9:10 AM: ---------------------------------------------------------- Hi [~linyiqun], [~adam.antal], thanks for your comments! Regarding the behavior against an unknown section, I would prefer logging a warn/error to throwing a descriptive IOException and aborting the program. The unknown section could be ignored in those cases. Thought? Patch v002 is uploaded to * Remove the change on adding a "UNKNOWN" element and related code. * Add the logic to check the return value of fromString() before the "switch..case" clause. * Add a new static public function called fromSection() in FSImageFormatProtobuf.SectionName and make it call fromString() internally, as I found all usages of fromString() are of the same pattern and could be abstracted into a new function. So remove the usage of fromString() and use fromSection() instead. By the way, I might need to change the summary of this JIRA as we do not intend to provide a default section as discussed. was (Author: water): Hi [~linyiqun], [~adam.antal], thanks for your comments! Regarding the behavior against an unknown section, I would prefer logging a warn/error to throwing a descriptive IOException and aborting the program. The unknown section could be ignored in those cases. Thought? Patch v002 is uploaded to * Remove the change on adding a "UNKNOWN" element and related code * Add a new static public function called fromSection() in FSImageFormatProtobuf.SectionName and make it call fromString() internally, as I found all usages of fromString() are of the same pattern and could be abstracted into a new function. By the way, I might need to change the summary of this JIRA as we do not intend to provide a default section as discussed. > Handle NPE when SectionName#fromString() returns null > ----------------------------------------------------- > > Key: HDFS-14172 > URL: https://issues.apache.org/jira/browse/HDFS-14172 > Project: Hadoop HDFS > Issue Type: Improvement > Reporter: Xiang Li > Assignee: Xiang Li > Priority: Minor > Attachments: HADOOP-14172.000.patch, HADOOP-14172.001.patch > > > In FSImageFormatProtobuf.SectionName#fromString(), as follows: > {code:java} > public static SectionName fromString(String name) { > for (SectionName n : values) { > if (n.name.equals(name)) > return n; > } > return null; > } > {code} > When the code meets an unknown section from the fsimage, the function will > return null. Callers always operates the return value with a "switch" clause, > like FSImageFormatProtobuf.Loader#loadInternal(), as: > {code:java} > switch (SectionName.fromString(n)) > {code} > NPE will be thrown here. > For self-protection, shall we add a default section name in the enum of > SectionName, like "UNKNOWN", to steer clear of NPE? -- This message was sent by Atlassian JIRA (v7.6.3#76005) --------------------------------------------------------------------- To unsubscribe, e-mail: hdfs-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: hdfs-issues-h...@hadoop.apache.org