slfan1989 commented on code in PR #5309:
URL: https://github.com/apache/hadoop/pull/5309#discussion_r1090779876


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/SharedCacheClientImpl.java:
##########
@@ -158,14 +158,8 @@ public void release(ApplicationId applicationId, String 
resourceKey)
   public String getFileChecksum(Path sourceFile)
       throws IOException {
     FileSystem fs = sourceFile.getFileSystem(this.conf);
-    FSDataInputStream in = null;
-    try {
-      in = fs.open(sourceFile);
+    try (FSDataInputStream in = fs.open(sourceFile)) {

Review Comment:
   The try-with-resources statement is a try statement that declares one or 
more resources. A resource is an object that must be closed after the program 
is finished with it. The try-with-resources statement ensures that each 
resource is closed at the end of the statement. Any object that implements 
java.lang.AutoCloseable, which includes all objects which implement 
java.io.Closeable, can be used as a resource.
   
   `FSDataInputStream` implement `java.io.Closeable`,  Can we add a junit Test?



-- 
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: common-issues-unsubscr...@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to