hadoop-hdfs-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Xiang Li (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (HDFS-14172) Return a default SectionName to avoid NPE
Date Tue, 25 Dec 2018 03:39:00 GMT

     [ https://issues.apache.org/jira/browse/HDFS-14172?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Xiang Li updated HDFS-14172:
----------------------------
    Description: 
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.
Shall we add a default section name in the enum of SectionName, like "UNKNOWN", to steer clear
of NPE?

> Return a default SectionName to avoid NPE
> -----------------------------------------
>
>                 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
>
> 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.
> 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-unsubscribe@hadoop.apache.org
For additional commands, e-mail: hdfs-issues-help@hadoop.apache.org


Mime
View raw message