Apache9 commented on code in PR #5064:
URL: https://github.com/apache/hbase/pull/5064#discussion_r1121632971


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java:
##########
@@ -203,20 +202,21 @@ public static FSDataOutputStream create(Configuration 
conf, FileSystem fs, Path
         short replication = 
Short.parseShort(conf.get(ColumnFamilyDescriptorBuilder.DFS_REPLICATION,
           
String.valueOf(ColumnFamilyDescriptorBuilder.DEFAULT_DFS_REPLICATION)));
         try {
-          return (FSDataOutputStream) (DistributedFileSystem.class
-            .getDeclaredMethod("create", Path.class, FsPermission.class, 
boolean.class, int.class,
-              short.class, long.class, Progressable.class, 
InetSocketAddress[].class)
-            .invoke(backingFs, path, perm, true, 
CommonFSUtils.getDefaultBufferSize(backingFs),
-              replication > 0 ? replication : 
CommonFSUtils.getDefaultReplication(backingFs, path),
-              CommonFSUtils.getDefaultBlockSize(backingFs, path), null, 
favoredNodes));
-        } catch (InvocationTargetException ite) {
-          // Function was properly called, but threw it's own exception.
-          throw new IOException(ite.getCause());
-        } catch (NoSuchMethodException e) {
+          DistributedFileSystem dfs = (DistributedFileSystem) backingFs;
+          DistributedFileSystem.HdfsDataOutputStreamBuilder builder = 
dfs.createFile(path)
+            .permission(perm).create().overwrite(true)
+            .bufferSize(CommonFSUtils.getDefaultBufferSize(backingFs))
+            .replication(
+              replication > 0 ? replication : 
CommonFSUtils.getDefaultReplication(backingFs, path))
+            .blockSize(CommonFSUtils.getDefaultBlockSize(backingFs, path));
+          if (favoredNodes != null) {
+            builder.favoredNodes(favoredNodes);
+          }
+          builder.recursive();
+          return builder.build();
+        } catch (IllegalArgumentException | SecurityException e) {

Review Comment:
   Typically we should not catch RuntimeException. Here, the 
IllegalArgumentException means we misuse the builder API, for exmaple, forget 
to specify some necessary parameters. We should fix our code instead of 
catching the exception and going on.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to