https://bz.apache.org/bugzilla/show_bug.cgi?id=65710

--- Comment #8 from Christopher Schultz <ch...@christopherschultz.net> ---
(In reply to promenader from comment #5)
>     public String upload(@RequestParam("file") MultipartFile file){
>         try{
>             InputStream inputStream =  file.getInputStream();
>         }catch (IOException e){
>             e.printStackTrace();
>         }

No "finally" block?

I mean... you are leaking the fd right there in your code. Sure, the JVM should
eventually GC this reference, but you aren't even trying.

What happens if you do it properly:

    InputStream inputStream = null;
    try {
        inputStream =  file.getInputStream();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if(null != inputStream) try { inputStream.close(); }
            catch (IOException ioe) { ioe.printStackTrace(); }
    }

Or, if you are using a modern Java version:

    try(InputStream inputStream = file.getInputStream()) {
        // do whatever
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to