[jira] [Comment Edited] (HDFS-14172) Avoid NPE when SectionName#fromString() returns null
[ https://issues.apache.org/jira/browse/HDFS-14172?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16763199#comment-16763199 ] Yiqun Lin edited comment on HDFS-14172 at 2/8/19 1:05 AM: -- Almost looks good to me, [~water]. One minor comment; {code:java} SectionName sectionName = SectionName.fromString(n); +if (sectionName == null) { + throw new IOException("Unrecognized section " + n); +} switch (SectionName.fromString(n)) { {code} Can we reuse sectionName to replace the {{SectionName.fromString}} used in switch like other places we did? was (Author: linyiqun): Almost looks good to me, [~water]. One minor comment; {code:java} SectionName sectionName = SectionName.fromString(n); +if (sectionName == null) { + throw new IOException("Unrecognized section " + n); +} switch (SectionName.fromString(n)) { {code} Can we reuse sectionName to replace the {{SectionName.fromString }} used in switch like other places we did? > Avoid 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, > HADOOP-14172.002.patch, HADOOP-14172.003.patch, HADOOP-14172.004.patch, > HADOOP-14172.005.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. -- 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
[jira] [Comment Edited] (HDFS-14172) Avoid NPE when SectionName#fromString() returns null
[ https://issues.apache.org/jira/browse/HDFS-14172?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16763199#comment-16763199 ] Yiqun Lin edited comment on HDFS-14172 at 2/8/19 1:04 AM: -- Almost looks good to me, [~water]. One minor comment; {code:java} SectionName sectionName = SectionName.fromString(n); +if (sectionName == null) { + throw new IOException("Unrecognized section " + n); +} switch (SectionName.fromString(n)) { {code} Can we reuse sectionName to replace the {{SectionName.fromString }} used in switch like other places we did? was (Author: linyiqun): Almost looks good to me, [~water]. One minor comment; {code:java} SectionName sectionName = SectionName.fromString(n); +if (sectionName == null) { + throw new IOException("Unrecognized section " + n); +} switch (SectionName.fromString(n)) { {code} Can we reuse sectionName to replace the {{SectionName.fromString}} like other places we did? > Avoid 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, > HADOOP-14172.002.patch, HADOOP-14172.003.patch, HADOOP-14172.004.patch, > HADOOP-14172.005.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. -- 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
[jira] [Comment Edited] (HDFS-14172) Avoid NPE when SectionName#fromString() returns null
[ https://issues.apache.org/jira/browse/HDFS-14172?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16763199#comment-16763199 ] Yiqun Lin edited comment on HDFS-14172 at 2/8/19 1:03 AM: -- Almost looks good to me, [~water]. One minor comment; {code:java} SectionName sectionName = SectionName.fromString(n); +if (sectionName == null) { + throw new IOException("Unrecognized section " + n); +} switch (SectionName.fromString(n)) { {code} Can we reuse sectionName to replace the {{SectionName.fromString}} like other places we did? was (Author: linyiqun): Almost looks good to me, [~water]. One minor comment; {code:java} SectionName sectionName = SectionName.fromString(n); +if (sectionName == null) { + throw new IOException("Unrecognized section " + n); +} switch (SectionName.fromString(n)) { {code} Can we reuse sectionName to replace the {{SectionName.fromString(n)}} like other places we did? > Avoid 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, > HADOOP-14172.002.patch, HADOOP-14172.003.patch, HADOOP-14172.004.patch, > HADOOP-14172.005.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. -- 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
[jira] [Comment Edited] (HDFS-14172) Avoid NPE when SectionName#fromString() returns null
[ https://issues.apache.org/jira/browse/HDFS-14172?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16757079#comment-16757079 ] Yiqun Lin edited comment on HDFS-14172 at 1/31/19 9:58 AM: --- Yes, [~water]. Some unrelated change can all be reverted, :). was (Author: linyiqun): Yes, [~water]. Some unrelated can all be reverted, :). > Avoid 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, > HADOOP-14172.002.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
[jira] [Comment Edited] (HDFS-14172) Avoid NPE when SectionName#fromString() returns null
[ https://issues.apache.org/jira/browse/HDFS-14172?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16757056#comment-16757056 ] Yiqun Lin edited comment on HDFS-14172 at 1/31/19 9:32 AM: --- {quote}Regarding the behavior against an unknown section, I would prefer logging a warn/error to throwing a descriptive IOException and aborting the program. {quote} Re-looking into this, as HDFS-7076 is not merged, I think a descriptive IOException and aborting the program will be a more appropriate way. I mean that, it's safe for NN that it loads an unknown section and it should aborts the program. So a descriptive IOException throwing should be enough, can we revert additional change and make this JIRA more clear, [~water]? {code:java} SectionName sectionName = SectionName.fromString(n); if (sectionName == null) { throw new IOException("Unrecognized section " + n); } switch (sectionName) { case NS_INFO: loadNameSystemSection(in); break; ... {code} was (Author: linyiqun): {quote}Regarding the behavior against an unknown section, I would prefer logging a warn/error to throwing a descriptive IOException and aborting the program. {quote} Re-looking into this, as HDFS-7076 is not merged, I think a descriptive IOException and aborting the program will be a more appropriate way. I mean that, it's safe for NN that it loads an unknown section and it should aborts the program. So a descriptive IOException throwing should be enough, can we revert additional change and make this JIRA more clear, [~water]? {code:java} SectionName sectionName = SectionName.fromString(n); if (sectionName == null) { throw new IOException("Unrecognized section {}" + n); } switch (sectionName) { case NS_INFO: loadNameSystemSection(in); break; ... {code} > Avoid 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, > HADOOP-14172.002.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
[jira] [Comment Edited] (HDFS-14172) Avoid NPE when SectionName#fromString() returns null
[ https://issues.apache.org/jira/browse/HDFS-14172?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16757056#comment-16757056 ] Yiqun Lin edited comment on HDFS-14172 at 1/31/19 9:35 AM: --- {quote}Regarding the behavior against an unknown section, I would prefer logging a warn/error to throwing a descriptive IOException and aborting the program. {quote} Re-looking into this, as HDFS-7076 is not merged, I think a descriptive IOException and aborting the program will be a more appropriate way. I mean that, it's safe for NN that it loads an unknown section and it should aborts the program. So a descriptive IOException throwing should be enough, can we revert additional change and make this JIRA more clear, [~water]? We would be more carefully to modify these part of logic. {code:java} SectionName sectionName = SectionName.fromString(n); if (sectionName == null) { throw new IOException("Unrecognized section " + n); } switch (sectionName) { case NS_INFO: loadNameSystemSection(in); break; ... {code} was (Author: linyiqun): {quote}Regarding the behavior against an unknown section, I would prefer logging a warn/error to throwing a descriptive IOException and aborting the program. {quote} Re-looking into this, as HDFS-7076 is not merged, I think a descriptive IOException and aborting the program will be a more appropriate way. I mean that, it's safe for NN that it loads an unknown section and it should aborts the program. So a descriptive IOException throwing should be enough, can we revert additional change and make this JIRA more clear, [~water]? {code:java} SectionName sectionName = SectionName.fromString(n); if (sectionName == null) { throw new IOException("Unrecognized section " + n); } switch (sectionName) { case NS_INFO: loadNameSystemSection(in); break; ... {code} > Avoid 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, > HADOOP-14172.002.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