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

Colin Patrick McCabe edited comment on HDFS-10415 at 6/1/16 12:09 AM:
----------------------------------------------------------------------

The subclass can change the configuration that gets passed to the superclass.

{code}
class SuperClass {
  SuperClass(Configuration conf) {
    ... initialize superclass part of the object ...
  }
}

class SubClass extends SuperClass {
  SubClass(Configuration conf) {
    super(changeConf(conf));
    ... initialize my part of the object ...
  }

  private static Configuration changeConf(Configuration conf) {
    Configuration nconf = new Configuration(conf);
    nconf.set("foo", "bar");
    return nconf;
  }
}
{code}

Having a separate init() method is a well-known antipattern.  Initialization 
belongs in the constructor.  The only time a separate init method is really 
necessary is if you're using a dialect of C++ that doesn't support exceptions.


was (Author: cmccabe):
The subclass can change the configuration that gets passed to the superclass.

class SuperClass {
  SuperClass(Configuration conf) {
    ... initialize superclass part of the object ...
  }
}

class SubClass extends SuperClass {
  SubClass(Configuration conf) {
    super(changeConf(conf));
    ... initialize my part of the object ...
  }

  private static Configuration changeConf(Configuration conf) {
    Configuration nconf = new Configuration(conf);
    nconf.set("foo", "bar");
    return nconf;
  }
}

Having a separate init() method is a well-known antipattern.  Initialization 
belongs in the constructor.  The only time a separate init method is really 
necessary is if you're using a dialect of C++ that doesn't support exceptions.

> TestDistributedFileSystem#MyDistributedFileSystem attempts to set up 
> statistics before initialize() is called
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: HDFS-10415
>                 URL: https://issues.apache.org/jira/browse/HDFS-10415
>             Project: Hadoop HDFS
>          Issue Type: Bug
>          Components: test
>    Affects Versions: 2.8.0
>         Environment: jenkins
>            Reporter: Sangjin Lee
>            Assignee: Mingliang Liu
>         Attachments: HDFS-10415-branch-2.000.patch, 
> HDFS-10415-branch-2.001.patch, HDFS-10415.000.patch
>
>
> {noformat}
> Tests run: 24, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 51.096 sec 
> <<< FAILURE! - in org.apache.hadoop.hdfs.TestDistributedFileSystem
> testDFSCloseOrdering(org.apache.hadoop.hdfs.TestDistributedFileSystem)  Time 
> elapsed: 0.045 sec  <<< ERROR!
> java.lang.NullPointerException: null
>       at 
> org.apache.hadoop.hdfs.DistributedFileSystem.delete(DistributedFileSystem.java:790)
>       at 
> org.apache.hadoop.fs.FileSystem.processDeleteOnExit(FileSystem.java:1417)
>       at org.apache.hadoop.fs.FileSystem.close(FileSystem.java:2084)
>       at 
> org.apache.hadoop.hdfs.DistributedFileSystem.close(DistributedFileSystem.java:1187)
>       at 
> org.apache.hadoop.hdfs.TestDistributedFileSystem.testDFSCloseOrdering(TestDistributedFileSystem.java:217)
> {noformat}
> This is with Java 8 on Mac. It passes fine on trunk. I haven't tried other 
> combinations. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to