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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to