From c1163974763652fed86c1559b169a83923f91d1d Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 21 Dec 2015 13:55:42 +0000
Subject: [PATCH] Converted try/finally Closeable.close() (or Utils.closeSilently()) into try-with-resources

---
 opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/FileBasedArgument.java |   28 +++++++++-------------------
 1 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/FileBasedArgument.java b/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/FileBasedArgument.java
index fd96b58..8d71a38 100644
--- a/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/FileBasedArgument.java
+++ b/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/FileBasedArgument.java
@@ -28,11 +28,12 @@
 
 import static com.forgerock.opendj.cli.CliMessages.*;
 import static com.forgerock.opendj.util.StaticUtils.getExceptionMessage;
-import static org.forgerock.util.Utils.closeSilently;
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileReader;
+import java.io.IOException;
 import java.util.LinkedHashMap;
 
 import org.forgerock.i18n.LocalizableMessage;
@@ -195,31 +196,20 @@
             return false;
         }
 
-        // Open the file for reading.
-        BufferedReader reader;
-        try {
-            reader = new BufferedReader(new FileReader(valueFile));
-        } catch (final Exception e) {
-            invalidReason.append(ERR_FILEARG_CANNOT_OPEN_FILE.get(valueString, getName(),
-                    getExceptionMessage(e)));
-            return false;
-        }
-
-        // Read the first line and close the file.
+        // Open the file, read the first line and close the file.
         String line;
-        try {
+        try (BufferedReader reader = new BufferedReader(new FileReader(valueFile))) {
             line = reader.readLine();
-        } catch (final Exception e) {
-            invalidReason.append(ERR_FILEARG_CANNOT_READ_FILE.get(valueString, getName(),
-                    getExceptionMessage(e)));
+        } catch (final FileNotFoundException e) {
+            invalidReason.append(ERR_FILEARG_CANNOT_OPEN_FILE.get(valueString, getName(), getExceptionMessage(e)));
             return false;
-        } finally {
-            closeSilently(reader);
+        } catch (final IOException e) {
+            invalidReason.append(ERR_FILEARG_CANNOT_READ_FILE.get(valueString, getName(), getExceptionMessage(e)));
+            return false;
         }
 
         // If the line read is null, then that means the file was empty.
         if (line == null) {
-
             invalidReason.append(ERR_FILEARG_EMPTY_FILE.get(valueString, getName()));
             return false;
         }

--
Gitblit v1.10.0