You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/11/21 15:46:35 UTC
[commons-validator] branch master updated: Use try-with-resource.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-validator.git
The following commit(s) were added to refs/heads/master by this push:
new 5c50617 Use try-with-resource.
5c50617 is described below
commit 5c50617a69bfe81c893f51b8eaf4a7a9120f423b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Nov 21 10:46:30 2020 -0500
Use try-with-resource.
---
.../org/apache/commons/validator/AbstractCommonTest.java | 9 +--------
.../java/org/apache/commons/validator/ExtensionTest.java | 9 +--------
.../validator/routines/checkdigit/IBANCheckDigitTest.java | 12 +++---------
3 files changed, 5 insertions(+), 25 deletions(-)
diff --git a/src/test/java/org/apache/commons/validator/AbstractCommonTest.java b/src/test/java/org/apache/commons/validator/AbstractCommonTest.java
index da2791c..cbf527a 100644
--- a/src/test/java/org/apache/commons/validator/AbstractCommonTest.java
+++ b/src/test/java/org/apache/commons/validator/AbstractCommonTest.java
@@ -45,15 +45,8 @@ abstract public class AbstractCommonTest extends TestCase {
*/
protected void loadResources(String file) throws IOException, SAXException {
// Load resources
- InputStream in = null;
-
- try {
- in = this.getClass().getResourceAsStream(file);
+ try (InputStream in = this.getClass().getResourceAsStream(file)) {
resources = new ValidatorResources(in);
- } finally {
- if (in != null) {
- in.close();
- }
}
}
}
diff --git a/src/test/java/org/apache/commons/validator/ExtensionTest.java b/src/test/java/org/apache/commons/validator/ExtensionTest.java
index 8658322..2b55f86 100644
--- a/src/test/java/org/apache/commons/validator/ExtensionTest.java
+++ b/src/test/java/org/apache/commons/validator/ExtensionTest.java
@@ -73,15 +73,8 @@ public class ExtensionTest extends TestCase {
@Override
protected void setUp() throws Exception {
// Load resources
- InputStream in = null;
-
- try {
- in = this.getClass().getResourceAsStream("ExtensionTest-config.xml");
+ try (InputStream in = this.getClass().getResourceAsStream("ExtensionTest-config.xml")) {
resources = new ValidatorResources(in);
- } finally {
- if (in != null) {
- in.close();
- }
}
}
diff --git a/src/test/java/org/apache/commons/validator/routines/checkdigit/IBANCheckDigitTest.java b/src/test/java/org/apache/commons/validator/routines/checkdigit/IBANCheckDigitTest.java
index a2253b0..f91485a 100644
--- a/src/test/java/org/apache/commons/validator/routines/checkdigit/IBANCheckDigitTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/checkdigit/IBANCheckDigitTest.java
@@ -230,11 +230,9 @@ public class IBANCheckDigitTest extends AbstractCheckDigitTest {
}
public void testOther() throws Exception {
- BufferedReader rdr = null;
- try {
- rdr = new BufferedReader(
- new InputStreamReader(
- this.getClass().getResourceAsStream("IBANtests.txt"),"ASCII"));
+ try (BufferedReader rdr = new BufferedReader(
+ new InputStreamReader(
+ this.getClass().getResourceAsStream("IBANtests.txt"),"ASCII"))) {
String line;
while((line=rdr.readLine()) != null) {
if (!line.startsWith("#") && line.length() > 0) {
@@ -246,10 +244,6 @@ public class IBANCheckDigitTest extends AbstractCheckDigitTest {
}
}
}
- } finally {
- if (rdr != null) {
- rdr.close();
- }
}
}
}