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/ArgumentParser.java | 19 +++++++------------
1 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java b/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
index 0e4fdf8..9ba847a 100644
--- a/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
+++ b/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
@@ -54,7 +54,6 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
-import org.forgerock.util.Utils;
/**
* This class defines a utility that can be used to deal with command-line
@@ -425,13 +424,13 @@
}
// We have a location for the properties file.
- final Properties argumentProperties = new Properties();
- final String scriptName = getScriptName();
try {
+ final Properties argumentProperties = new Properties();
+ final String scriptName = getScriptName();
final Properties p = new Properties();
- final FileInputStream fis = new FileInputStream(propertiesFilePath);
- p.load(fis);
- fis.close();
+ try (final FileInputStream fis = new FileInputStream(propertiesFilePath)) {
+ p.load(fis);
+ }
for (final Enumeration<?> e = p.propertyNames(); e.hasMoreElements();) {
final String currentPropertyName = (String) e.nextElement();
@@ -449,12 +448,12 @@
argumentProperties.setProperty(propertyName.toLowerCase(), p
.getProperty(currentPropertyName));
}
+ return argumentProperties;
} catch (final Exception e) {
final LocalizableMessage message =
ERR_ARGPARSER_CANNOT_READ_PROPERTIES_FILE.get(propertiesFilePath, getExceptionMessage(e));
throw new ArgumentException(message, e);
}
- return argumentProperties;
}
/**
@@ -1384,9 +1383,7 @@
Properties argumentProperties = null;
- FileInputStream fis = null;
- try {
- fis = new FileInputStream(propertiesFile);
+ try (final FileInputStream fis = new FileInputStream(propertiesFile)) {
final Properties p = new Properties();
p.load(fis);
argumentProperties = p;
@@ -1396,8 +1393,6 @@
ERR_ARGPARSER_CANNOT_READ_PROPERTIES_FILE.get(propertiesFile, getExceptionMessage(e));
throw new ArgumentException(message, e);
}
- } finally {
- Utils.closeSilently(fis);
}
parseArguments(rawArguments, argumentProperties);
--
Gitblit v1.10.0