You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2019/11/17 17:34:43 UTC

[GitHub] [hbase] belugabehr commented on a change in pull request #836: HBASE-23308: Review of NullPointerExceptions

belugabehr commented on a change in pull request #836: HBASE-23308: Review of NullPointerExceptions
URL: https://github.com/apache/hbase/pull/836#discussion_r347148986
 
 

 ##########
 File path: hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/BackupDriver.java
 ##########
 @@ -187,10 +188,7 @@ public static void main(String[] args) throws Exception {
 
   @Override
   public int run(String[] args) throws IOException {
-    if (conf == null) {
-      LOG.error("Tool configuration is not initialized");
-      throw new NullPointerException("conf");
-    }
+    Objects.requireNonNull(conf, "Tool configuration is not initialized");
 
 Review comment:
   @saintstack Less code.  I also like the JavaDoc for the method.  I copy & paste its message to use the same helpful formatting. 
   
   Trying to introduce it so that others may stumble upon and learn.  Best used in this way:
   
   ```
   public MyClass(String val) {
     this.val = Objects.requireNonNull(val);
   }
   ```
   
   More concise than the alternative:
   
   ```
   public MyClass(String val) {
     if (val == null) {
       throw new NullPointerException();
     }
     this.val = val;
   }
   ```
   
   But if it's going to be used one way, might as well be used everywhere.  Pretty versatile that way.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services