You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/09/06 11:22:53 UTC

[GitHub] diecui1202 closed pull request #2414: [Dubbo-2413] Fix StreamUtils resource leak

diecui1202 closed pull request #2414: [Dubbo-2413] Fix StreamUtils resource leak
URL: https://github.com/apache/incubator-dubbo/pull/2414
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/io/StreamUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/io/StreamUtils.java
index 9b52286769..5798f020fb 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/io/StreamUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/io/StreamUtils.java
@@ -98,6 +98,7 @@ public void reset() throws IOException {
 
             @Override
             public void close() throws IOException {
+                is.close();
             }
         };
     }
@@ -199,6 +200,11 @@ public int available() throws IOException {
 
                 return available;
             }
+
+            @Override
+            public void close() throws IOException {
+                is.close();
+            }
         };
     }
 
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/io/StreamUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/io/StreamUtilsTest.java
index b4dc1b6182..2f8595fef8 100644
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/io/StreamUtilsTest.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/io/StreamUtilsTest.java
@@ -79,6 +79,8 @@ public void testMarkSupportedInputStream() throws Exception {
         is.reset();
         assertEquals(-1, is.read());
         assertEquals(-1, is.read());
+
+        is.close();
     }
 
     @Test
@@ -118,35 +120,54 @@ public void testLimitedInputStream() throws Exception {
     @Test(expected = IOException.class)
     public void testMarkInputSupport() throws IOException {
         InputStream is = StreamUtilsTest.class.getResourceAsStream("/StreamUtilsTest.txt");
-        is = StreamUtils.markSupportedInputStream(new PushbackInputStream(is), 1);
-
-        is.mark(1);
-        int read = is.read();
-        assertThat(read, is((int) '0'));
-
-        is.skip(1);
-        is.read();
+        try {
+            is = StreamUtils.markSupportedInputStream(new PushbackInputStream(is), 1);
+
+            is.mark(1);
+            int read = is.read();
+            assertThat(read, is((int) '0'));
+
+            is.skip(1);
+            is.read();
+        } finally {
+            if (is != null) {
+                is.close();
+            }
+        }
     }
 
     @Test
-    public void testSkipForOriginMarkSupportInput() {
+    public void testSkipForOriginMarkSupportInput() throws IOException {
         InputStream is = StreamUtilsTest.class.getResourceAsStream("/StreamUtilsTest.txt");
         InputStream newIs = StreamUtils.markSupportedInputStream(is, 1);
 
         assertThat(newIs, is(is));
+        is.close();
     }
 
     @Test(expected = NullPointerException.class)
     public void testReadEmptyByteArray() throws IOException {
         InputStream is = StreamUtilsTest.class.getResourceAsStream("/StreamUtilsTest.txt");
-        is = StreamUtils.limitedInputStream(is, 2);
-        is.read(null, 0, 1);
+        try {
+            is = StreamUtils.limitedInputStream(is, 2);
+            is.read(null, 0, 1);
+        } finally {
+            if (is != null) {
+                is.close();
+            }
+        }
     }
 
     @Test(expected = IndexOutOfBoundsException.class)
     public void testReadWithWrongOffset() throws IOException {
         InputStream is = StreamUtilsTest.class.getResourceAsStream("/StreamUtilsTest.txt");
-        is = StreamUtils.limitedInputStream(is, 2);
-        is.read(new byte[1], -1, 1);
+        try {
+            is = StreamUtils.limitedInputStream(is, 2);
+            is.read(new byte[1], -1, 1);
+        } finally {
+            if (is != null) {
+                is.close();
+            }
+        }
     }
 }
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org