Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
-
None
-
This is a problem with the way the getClassFromStream method is coded. The problem is independent of the environment.
Description
The getClassFromStream(InputStream,String) method creates a ByteArrayOutputStream but fails to close it after it finishes using it. This could lead to memory leaks in long running programs using the "getClassFromStream" method. I am submitting a patch below. This code opens and uses the ByteArrayIOutputStream object "baos" inside a "try", and closes baos in a "finally" block.
Index: ContinuationClassLoader.java
===================================================================
— ContinuationClassLoader.java (revision 826428)
+++ ContinuationClassLoader.java (working copy)
@@ -350,7 +350,9 @@
*/
private Class getClassFromStream(InputStream stream, String classname)
throws IOException, SecurityException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ByteArrayOutputStream baos = null;
+ try { + baos = new ByteArrayOutputStream(); int bytesRead; byte[] buffer = new byte[BUFFER_SIZE]; @@ -360,6 +362,11 @@ byte[] classData = baos.toByteArray(); return defineClassFromData(classData, classname); + }finally
Unknown macro: {+ if ( baos != null ){ + baos.close(); + }+ }}
/**