Re: Findbugs and locks?
- From: Jeff Higgins <oohiggins@xxxxxxxxx>
- Date: Wed, 30 Jul 2008 08:46:48 -0400
Knute Johnson wrote:
Findbugs gives the warning "Method does not release lock on all exception paths" on a method like the one below. Could it be because the lock is from an array of locks and it can't determine which? Or is it because you could put code outside of the try/finally block that could leave without unlocking the lock? Any other ideas? It can't leave the method without unlocking can it?
Produces no bug reports using FindBugs 1.3.2.20080222
in Eclipse 3.3
import java.io.IOException;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
public class SSCCE {
ReentrantReadWriteLock lockArray[] =
new ReentrantReadWriteLock[5];
void method(int n) throws IOException {
if (n < lockArray.length) {
ReentrantReadWriteLock rrwl = lockArray[n];
WriteLock lock = rrwl.writeLock();
try {
lock.lock();
// do some disk I/O
} finally {
lock.unlock();
}
}
}
public static void main(String[] args) {
}
}
.
- Follow-Ups:
- Re: Findbugs and locks?
- From: Knute Johnson
- Re: Findbugs and locks?
- From: Jeff Higgins
- Re: Findbugs and locks?
- From: Lew
- Re: Findbugs and locks?
- References:
- Findbugs and locks?
- From: Knute Johnson
- Findbugs and locks?
- Prev by Date: Findbugs and locks?
- Next by Date: Re: Findbugs and locks?
- Previous by thread: Findbugs and locks?
- Next by thread: Re: Findbugs and locks?
- Index(es):
Relevant Pages
|