You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by bu...@apache.org on 2006/10/27 22:11:01 UTC

DO NOT REPLY [Bug 40835] New: - Unclosed FileInputStream in WebdavResource.putMethod

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=40835>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=40835

           Summary: Unclosed FileInputStream in WebdavResource.putMethod
           Product: Slide
           Version: 2.1
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P2
         Component: WebDAV client
        AssignedTo: slide-dev@jakarta.apache.org
        ReportedBy: dmx_dawg@hotmail.com


A FileInputStream in the putMethod(String path, File file) method of
WebdavResource is not closed.  On Windows (and any other OS that blocks writing
to open files) this will prevent editing of any file uploaded via this method
until the application that uploaded the file is exited.

See below for the simple fix (one can simply comment-out the old version of the
method and paste-in this one in its entirety).

Cheers!

Michael N. Christoff
dmx_dawg@hotmail.com


    /**
     * Execute the PUT method for the given path.
     *
     * October 22, 2006
     * Fixed error where FileInputStream not closed.
     *
     * @param path the server relative path to put the given file
     * @param file the filename to get on local.
     * @return true if the method is succeeded.
     * @exception HttpException
     * @exception IOException
     */
    public boolean putMethod(String path, File file)
        throws HttpException, IOException {

        setClient();
        PutMethod method = new PutMethod(URIUtil.encodePathQuery(path));
        generateIfHeader(method);
        if (getGetContentType() != null && !getGetContentType().equals(""))
            method.setRequestHeader("Content-Type", getGetContentType());
        long fileLength = file.length();
        method.setRequestContentLength(fileLength <= Integer.MAX_VALUE
                                       ? (int) fileLength
                                       : PutMethod.CONTENT_LENGTH_CHUNKED);
        FileInputStream fis = new FileInputStream(file);
        method.setRequestBody(fis);
        generateTransactionHeader(method);
        int statusCode = client.executeMethod(method);

        setStatusCode(statusCode);

        fis.close();  // <--- simple update to code

        return (statusCode >= 200 && statusCode < 300) ? true : false;
    }

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org


DO NOT REPLY [Bug 40835] - Unclosed FileInputStream in WebdavResource.putMethod

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=40835>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=40835


dmx_dawg@hotmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |




------- Additional Comments From dmx_dawg@hotmail.com  2007-02-08 14:38 -------
I realize now that my proposed fix for this is inadequate.  The problem will
still arise if an exception occurs at any time after the FileInputStream 'fis'
is opened but before it is closed.  In that case, the method will exit without
having called fis.close().

Below is a solution that will ensure the stream closes even in the event of an
exception:

    public boolean putMethod(String path, File file)
        throws HttpException, IOException {


        FileInputStream fis = null;  // <- * declared outside of try block *
        try {        // <----------------- * try block added *


            setClient();
            PutMethod method = new PutMethod(URIUtil.encodePathQuery(path));
            generateIfHeader(method);
            if (getGetContentType() != null && !getGetContentType().equals(""))
                method.setRequestHeader("Content-Type", getGetContentType());
            long fileLength = file.length();
            method.setRequestContentLength(fileLength <= Integer.MAX_VALUE
                                           ? (int) fileLength
                                           : PutMethod.CONTENT_LENGTH_CHUNKED);
            fis = new FileInputStream(file);
            method.setRequestBody(fis);
            generateTransactionHeader(method);
            int statusCode = client.executeMethod(method);

            setStatusCode(statusCode);
            return (statusCode >= 200 && statusCode < 300) ? true : false;
            

        } finally {
            if(fis != null)      // <---- * stream closed in finally block *
                fis.close();
        }


    } 

By closing the stream in the finally block we gaurantee the stream will close.

Note: This is also an issue for putMethod(String, File) of the same class.  I
will submit a bug report and fix for this shortly.



Cheers!


Mike N. Christoff
dmx_dawg@hotmail.com

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org


DO NOT REPLY [Bug 40835] - Unclosed FileInputStream in WebdavResource.putMethod

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=40835>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=40835


antoine@apache.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED




------- Additional Comments From antoine@apache.org  2007-02-11 19:22 -------
fix just committed in SVN, thanks

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org


DO NOT REPLY [Bug 40835] - Unclosed FileInputStream in WebdavResource.putMethod

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=40835>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=40835


antoine@apache.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Additional Comments From antoine@apache.org  2006-10-28 16:20 -------
Thanks for your bug report.
Now fixed in SVN.
Will be available for the next release.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org


DO NOT REPLY [Bug 40835] - Unclosed FileInputStream in WebdavResource.putMethod

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=40835>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=40835


antoine@apache.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |2.2




-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org