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-logging.git
The following commit(s) were added to refs/heads/master by this push: new 37cd44c Test does not close input stream 37cd44c is described below commit 37cd44ccb20e55aa835c68777fb1bd522934fd3e Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Wed Aug 14 08:48:28 2024 -0400 Test does not close input stream --- .../org/apache/commons/logging/LoadTestCase.java | 29 ++++++++-------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/test/java/org/apache/commons/logging/LoadTestCase.java b/src/test/java/org/apache/commons/logging/LoadTestCase.java index 339bfd2..b9db728 100644 --- a/src/test/java/org/apache/commons/logging/LoadTestCase.java +++ b/src/test/java/org/apache/commons/logging/LoadTestCase.java @@ -16,12 +16,16 @@ */ package org.apache.commons.logging; +import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; import junit.framework.TestCase; +import org.apache.commons.io.IOUtils; + /** * test to emulate container and application isolated from container */ @@ -45,35 +49,22 @@ public class LoadTestCase extends TestCase { } private Class<?> def(final String name) throws ClassNotFoundException { - Class<?> result = classes.get(name); if (result != null) { return result; } - try { - final ClassLoader cl = this.getClass().getClassLoader(); final String classFileName = name.replace('.', '/') + ".class"; - final java.io.InputStream is = cl.getResourceAsStream(classFileName); - final java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream(); - - while (is.available() > 0) { - out.write(is.read()); + try (InputStream is = cl.getResourceAsStream(classFileName)) { + final byte[] data = IOUtils.toByteArray(is); + result = super.defineClass(name, data, 0, data.length); + classes.put(name, result); + return result; } - - final byte[] data = out.toByteArray(); - - result = super.defineClass(name, data, 0, data.length); - classes.put(name, result); - - return result; - - } catch (final java.io.IOException ioe) { - + } catch (final IOException ioe) { throw new ClassNotFoundException(name + " caused by " + ioe.getMessage()); } - } // not very trivial to emulate we must implement "findClass",