• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[Fortify] "sometimes fails to release a system resource allocated by getBinaryStream()"

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my Java application I have a code like this.



When we run fortify against this code, it says ...
sometimes fails to release a system resource allocated by getBinaryStream()

How to fix this error ?
Kindly give me some inputs.

Best Regards
Krishna
 
Vignesh Ganesh
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought of doing this way ...



I didn't write the catch because, the exception propagates to the caller.

Please suggest me if it is right way of doing it ?

Best Regards
Krishan
 
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

You don't provide much details in order for us to help you.

Anyway, just close your input stream by calling close() on it when you are done with it. This is good practice. You should always call close() on streams as soon as you are done using them to release system resources as early as possible.. This might be all there is to it.
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vignesh Ganesh wrote:I thought of doing this way ...



I didn't write the catch because, the exception propagates to the caller.

Please suggest me if it is right way of doing it ?

Best Regards
Krishan



yes this should do although, since I am hyper paranoid, I would probably go for:


Of course, "is" will have to be declared outside your try block.
InputStream is;
try { ......


 
Vignesh Ganesh
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree, my bad. Surrounding the close() with try...catch is the best option as you suggested.
Thanks a lot.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using Java 7 or later you should look at using try-with-resources. See https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
reply
    Bookmark Topic Watch Topic
  • New Topic