Re: Findbugs and locks?
- From: Knute Johnson <nospam@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 30 Jul 2008 22:49:49 -0700
Daniel Pitts wrote:
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.
If the lock throws an exception, how can it be locked?
--
Knute Johnson
email s/nospam/knute2008/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
.
- Follow-Ups:
- Re: Findbugs and locks?
- From: Jeff Higgins
- 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
- Re: Findbugs and locks?
- From: Daniel Pitts
- 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
|