Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find all instances and objects in my code that are not closed?

My team has quite a huge amount of code. Recently I have found some objects that weren't closed properly.
How can i find all the instances that are not closed or not inside a try-with-resources block?
Some objects like Statement, ResultSet are not showing warning messages for it, even.

Is there an extension tool for showing all this occurrences?
I'm using Eclipse.

like image 492
Barak Kedem Avatar asked Oct 18 '22 17:10

Barak Kedem


1 Answers

Static code analysis tools like Sonar should find all those occurrences and warn you about them.
IDEA IntelliJ's inspection profiles also includes some rules for that (Settings > Editor > Inspections > Java > Resource management issues, or just filter by "close" inside Inspections).

I see that you're using Eclipse. You can probably install the FindBugs Eclipse plugin, which includes a couple of rules to check if resources are properly closed.

like image 114
walen Avatar answered Oct 21 '22 04:10

walen