Bug 721121 - Unsatisfied obligation to close InputStream in Apache plug-in
Summary: Unsatisfied obligation to close InputStream in Apache plug-in
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: RHQ Project
Classification: Other
Component: Plugins
Version: 4.1
Hardware: All
OS: All
medium
medium vote
Target Milestone: ---
: ---
Assignee: Robert Buck
QA Contact: Mike Foley
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-07-13 19:16 UTC by Mike Foley
Modified: 2012-02-07 19:25 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-02-07 19:25:42 UTC


Attachments (Terms of Use)

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


Note You need to log in before you can comment on or make changes to this bug.