Bug 721121

Summary: Unsatisfied obligation to close InputStream in Apache plug-in
Product: [Other] RHQ Project Reporter: Mike Foley <mfoley>
Component: PluginsAssignee: Robert Buck <rbuck>
Status: CLOSED CURRENTRELEASE QA Contact: Mike Foley <mfoley>
Severity: medium Docs Contact:
Priority: medium    
Version: 4.1CC: hrupp
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-02-07 19:25:42 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Mike Foley 2011-07-13 19:16:37 UTC
Description of problem:  Unsatisfied obligation to close InputStream in Apache plug-in .... if an exception is thrown.  Specifically, 

org.rhq.plugins.apache.ApachePluginLifecycleListener.copyFile()

Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1.
2.
3.
  
Actual results:
Unsatisifed obligation to close InputStream in the event an exception is thrown

Expected results:
Programmatically closing InputStream under all circumstances (including if an exception is thrown).

Additional info:
public void copyFile(InputStream in,File destination) throws Exception{
        
        if (!destination.canWrite())
           throw new Exception("Creating of temporary file for lens failed. Destination file "
                   + destination.getAbsolutePath()+" is not accessible.");

       OutputStream out = new FileOutputStream(destination);
   
       byte[] buf = new byte[1024];
       int length;

       while ((length = in.read(buf)) > 0) {
           out.write(buf, 0, length);
       }
       
       in.close();
       out.close();

    }

Comment 1 Mike Foley 2011-10-06 19:04:09 UTC
bob ... u closed all these input streams en masse ... right?

Comment 2 Robert Buck 2011-10-07 13:33:50 UTC
I did, but apparently this is one that crept by me. let me fix this, this is a
two second fix.

Comment 3 Robert Buck 2011-10-07 14:34:49 UTC
commit 985e7fab93e5ed3b72c88ce23a1f1200d8bb5096
Author: Robert Buck <rbuck>
Date:   2011-10-07 10:33:52 -0400
[BZ 721121] Fix IO stream resource leak.

Comment 4 Mike Foley 2012-02-07 19:25:42 UTC
changing status of VERIFIED BZs for JON 2.4.2 and JON 3.0 to CLOSED/CURRENTRELEASE