Please refer to the following code snippet(stripped off the redundant part to highlight the problematic case):
FindBugs is complaining that "Method does not release lock on all paths" . Is this a false positive? If not, how to fix this?
try{
someLock.lock();
//do something
} finally{
if (someLock.isLocked())
someLock.unlock();
}
If isLocked()
throws something, then you don't unlock.
I don't think it's probable to have isLocked
throwing an exception but when you lock, you must unlock, there is no point in testing. So why not use the standard pattern described in the javadoc :
someLock.lock();
try{
//do something
} finally{
someLock.unlock();
}
So I'd said