#315 Check for connection close

Future
closed
nobody
Check (274)
5
2015-10-22
2004-08-25
Prashant
No

Hi,

Please let me know whether there is a check available
for checking whether a database connection object is
closed or not. I went through the javadoc, but could not
find one.

If the same is not available, could you please advice as
to how it needs to be implemented in regards to the
classes that need to be used to implement the same.

Thanks in advance.

Best Regards,
Prashant

Discussion

  • Lars Kühne

    Lars Kühne - 2004-08-28

    Logged In: YES
    user_id=401384

    Such a check is not available. It would require checking the
    control flow of your program, and I'm not sure it's possible
    to write such a check in a way that is 100% correct (finds
    all problems, no false alarms).

    Threre are ways to avoid these kinds of problems, but they
    require a bit of dicipline from the developer
    - manual code review / pair programming
    - unit tests with mock connections (e.g. easymock) that
    trigger non-typical control flow by throwing exceptions

    Maybe Oliver has other suggestions...

     
  • Lars Kühne

    Lars Kühne - 2004-08-28

    Logged In: YES
    user_id=401384

    Oh, I just saw that the findbugs tool has a check that tries
    to find these problems:

    http://findbugs.sourceforge.net/bugDescriptions.html#ODR_OPEN_DATABASE_RESOURCE

    Not sure whether it's results are 100% accurate, though
    ("Method MAY fail to close database resource"), but it
    should at least give you a list of places that you need to
    look at...

     
  • Roman Ivanov

    Roman Ivanov - 2015-10-22

    Checkstyle can not do validation like requested. Checkstyle do validation of one file content only.

     
  • Roman Ivanov

    Roman Ivanov - 2015-10-22
    • status: open --> closed
    • Group: --> Future
     

Log in to post a comment.