Re: Findbugs and locks?
- From: Daniel Pitts <newsgroup.spamfilter@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 30 Jul 2008 17:41:30 -0700
Knute Johnson wrote:
Ah but look at what does!
static void method(int n) throws IOException {
// WriteLock lock = lockArray[n].writeLock();
// lock.lock();
lockArray[n].writeLock().lock();
try {
// do some disk I/O
} finally {
// lock.unlock();
lockArray[n].writeLock().unlock();
}
}
I think it is a bug in findbugs. I think I'll drop them a line.
I don't think its a bug in findbugs.
The problem is that lockArray[n] might through an exception in the finally if the lockArray changes size. lockArray[n] might also be assigned a null at some point, so lockArray[n].writeLock() could through an NPE.
I think a better approach would be to have method take a Lock rather than an index into an array.
Hope this helps,
Daniel.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
.
- Follow-Ups:
- Re: Findbugs and locks?
- From: Knute Johnson
- Re: Findbugs and locks?
- References:
- Findbugs and locks?
- From: Knute Johnson
- Re: Findbugs and locks?
- From: Jeff Higgins
- Re: Findbugs and locks?
- From: Knute Johnson
- Re: Findbugs and locks?
- From: Jeff Higgins
- Re: Findbugs and locks?
- From: Knute Johnson
- Findbugs and locks?
- Prev by Date: Re: Findbugs and locks?
- Next by Date: Re: Findbugs and locks?
- Previous by thread: Re: Findbugs and locks?
- Next by thread: Re: Findbugs and locks?
- Index(es):
Relevant Pages
|