You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by pa...@apache.org on 2019/12/20 12:56:03 UTC

[commons-text] 01/02: UrlStringLookup: Close InputStream even if the InputStreamReader constructor throws an exception.

This is an automated email from the ASF dual-hosted git repository.

pascalschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git

commit b7052a259f91e7cc257b7cab26d24dd7f8273fb4
Author: Pascal Schumacher <pa...@gmx.net>
AuthorDate: Fri Dec 20 13:48:12 2019 +0100

    UrlStringLookup: Close InputStream even if the InputStreamReader constructor throws an exception.
---
 src/main/java/org/apache/commons/text/lookup/UrlStringLookup.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/text/lookup/UrlStringLookup.java b/src/main/java/org/apache/commons/text/lookup/UrlStringLookup.java
index 1c27736..1d0fb4d 100644
--- a/src/main/java/org/apache/commons/text/lookup/UrlStringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/UrlStringLookup.java
@@ -75,8 +75,8 @@ final class UrlStringLookup extends AbstractStringLookup {
             final int size = 8192;
             final StringWriter writer = new StringWriter(size);
             final char[] buffer = new char[size];
-            try (InputStreamReader reader = new InputStreamReader(new BufferedInputStream(url.openStream()),
-                    charsetName)) {
+            try (BufferedInputStream bis = new BufferedInputStream(url.openStream());
+                    InputStreamReader reader = new InputStreamReader(bis, charsetName)) {
                 int n;
                 while (-1 != (n = reader.read(buffer))) {
                     writer.write(buffer, 0, n);