Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Vignesh Ganesh
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Agree, my bad. Surrounding the close() with try...catch is the best option as you suggested.
Thanks a lot.
 
Tony Docherty
Bartender
Posts: 3264
81
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!