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

--- Comment #10 from promena...@163.com ---
(In reply to Christopher Schultz from comment #8)
> (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();
>     }

Yes. leaking the fd right here is on purpose. Just want to show when IOStream
closed failed. which Tomcat version will autorelease the linux handle.

-- 
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