hadoop-hdfs-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam Antal (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HDFS-14172) Avoid NPE when SectionName#fromString() returns null
Date Thu, 07 Feb 2019 11:34:00 GMT

    [ https://issues.apache.org/jira/browse/HDFS-14172?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16762583#comment-16762583

Adam Antal commented on HDFS-14172:

Thanks for the patch, [~water]. This looks quite clear now. 
The else part wasn't necessary indeed, as if the condition is true, an exception is thrown,
jumping over the rest of the function.
The brackets {} for every if clause are required though (the style checker also gave you a
warning about that).
One last thing from the checkstyle is that {{FSImageLoader.java:160}} line is too long (114).
Consider breaking it into two lines by the equal sign.

> 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
> 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(),
> {code:java}
> switch (SectionName.fromString(n))
> {code}
> NPE will be thrown here.

This message was sent by Atlassian JIRA

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

View raw message