Uploaded image for project: 'Commons Sandbox'
  1. Commons Sandbox
  2. SANDBOX-314

ContinuationClassLoader does not close output stream in getClassFromStream(InputStream,String)

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Javaflow
    • Labels:
      None
    • Environment:

      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(); + }+ }

        }

      /**

        Attachments

        1. ContinuationClassLoader.txt
          0.9 kB
          Subhajit DasGupta

          Activity

            People

            • Assignee:
              tcurdt Torsten Curdt
              Reporter:
              subhajit_dasgupta Subhajit DasGupta
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 0.5h
                0.5h
                Remaining:
                Remaining Estimate - 0.5h
                0.5h
                Logged:
                Time Spent - Not Specified
                Not Specified