You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mb...@apache.org on 2022/07/17 19:10:54 UTC
[db-jdo] 07/08: JDO-817 removing compiler warnings: try finally replaceable with try with resources
This is an automated email from the ASF dual-hosted git repository.
mbo pushed a commit to branch tck-compiler-warnings
in repository https://gitbox.apache.org/repos/asf/db-jdo.git
commit e2ee4008f14ed20a642755842b147f5ed64d3017
Author: Michael Bouschen <Mi...@akquinet.de>
AuthorDate: Sun Jul 17 20:35:28 2022 +0200
JDO-817 removing compiler warnings: try finally replaceable with try with resources
---
tck/src/main/java/org/apache/jdo/tck/JDO_Test.java | 9 ++------
.../org/apache/jdo/tck/util/ResultSummary.java | 27 ++++------------------
.../org/apache/jdo/tck/util/SystemCfgSummary.java | 9 ++------
3 files changed, 9 insertions(+), 36 deletions(-)
diff --git a/tck/src/main/java/org/apache/jdo/tck/JDO_Test.java b/tck/src/main/java/org/apache/jdo/tck/JDO_Test.java
index 2155543e..ae41ec1c 100644
--- a/tck/src/main/java/org/apache/jdo/tck/JDO_Test.java
+++ b/tck/src/main/java/org/apache/jdo/tck/JDO_Test.java
@@ -745,18 +745,13 @@ public abstract class JDO_Test extends TestCase {
if (file.exists())
// PMF supported options have been dumped before => return
return;
- PrintStream resultStream = null;
- try {
- resultStream = new PrintStream(new FileOutputStream(file));
+ try (PrintStream resultStream = new PrintStream(new FileOutputStream(file))) {
for (String supportedOption : supportedOptions) {
resultStream.println(supportedOption);
}
} catch (FileNotFoundException e) {
throw new JDOFatalException(
- "dumpSupportedOptions: cannot create file " + file.getName(), e);
- } finally {
- if (resultStream != null)
- resultStream.close();
+ "dumpSupportedOptions: cannot create file " + file.getName(), e);
}
}
diff --git a/tck/src/main/java/org/apache/jdo/tck/util/ResultSummary.java b/tck/src/main/java/org/apache/jdo/tck/util/ResultSummary.java
index 60357c53..648ba236 100644
--- a/tck/src/main/java/org/apache/jdo/tck/util/ResultSummary.java
+++ b/tck/src/main/java/org/apache/jdo/tck/util/ResultSummary.java
@@ -93,16 +93,11 @@ public class ResultSummary implements Serializable {
*/
static void appendTCKResultMessage(String directory, String message) {
String fileName = directory + RESULT_FILE_NAME;
- PrintStream resultStream = null;
- try {
- resultStream = new PrintStream(
- new FileOutputStream(fileName, true));
+ try (PrintStream resultStream = new PrintStream(
+ new FileOutputStream(fileName, true))) {
resultStream.println(message);
} catch (FileNotFoundException e) {
- throw new JDOFatalException("Cannot create file "+fileName, e);
- } finally {
- if (resultStream != null)
- resultStream.close();
+ throw new JDOFatalException("Cannot create file " + fileName, e);
}
}
@@ -129,15 +124,9 @@ public class ResultSummary implements Serializable {
private static ResultSummary load(String directory) {
ResultSummary result;
String fileName = directory + FILE_NAME_OF_RESULT_SUMMARY;
- ObjectInputStream ois = null;
try {
- try {
- ois = new ObjectInputStream(new FileInputStream(fileName));
+ try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileName))) {
result = (ResultSummary) ois.readObject();
- } finally {
- if (ois != null) {
- ois.close();
- }
}
} catch (FileNotFoundException e) {
result = null;
@@ -169,15 +158,9 @@ public class ResultSummary implements Serializable {
*/
private void save(String directory) {
String fileName = directory + FILE_NAME_OF_RESULT_SUMMARY;
- ObjectOutputStream oos = null;
try {
- try {
- oos = new ObjectOutputStream(new FileOutputStream(fileName));
+ try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName))) {
oos.writeObject(this);
- } finally {
- if (oos != null) {
- oos.close();
- }
}
} catch (FileNotFoundException e) {
throw new JDOFatalException(
diff --git a/tck/src/main/java/org/apache/jdo/tck/util/SystemCfgSummary.java b/tck/src/main/java/org/apache/jdo/tck/util/SystemCfgSummary.java
index 9fd3b5f2..1eef3fdf 100644
--- a/tck/src/main/java/org/apache/jdo/tck/util/SystemCfgSummary.java
+++ b/tck/src/main/java/org/apache/jdo/tck/util/SystemCfgSummary.java
@@ -80,16 +80,11 @@ public class SystemCfgSummary {
* @param message the message
*/
static void saveSystemInfo(String path, String message) {
- PrintStream resultStream = null;
- try {
- resultStream = new PrintStream(
- new FileOutputStream(path, true));
+ try (PrintStream resultStream = new PrintStream(
+ new FileOutputStream(path, true))) {
resultStream.println(message);
} catch (FileNotFoundException e) {
throw new JDOFatalException("Cannot create file " + path, e);
- } finally {
- if (resultStream != null)
- resultStream.close();
}
}
}