Re: Findbugs and locks?



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
.



Relevant Pages

  • Re: Aqualunging?
    ... Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ... Unlimited Access, Anonymous Accounts, Uncensored Broadband Access ... Country, I suppose. ... Actually I play in a few different venues. ...
    (rec.boats)
  • Re: Ill Stick to Boating, Thank-you...
    ... Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ... Unlimited Access, Anonymous Accounts, Uncensored Broadband Access ...
    (rec.boats)
  • Re: Ill Stick to Boating, Thank-you...
    ... Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ... Unlimited Access, Anonymous Accounts, Uncensored Broadband Access ...
    (rec.boats)
  • Re: Well, I broke down...
    ... Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ... Unlimited Access, Anonymous Accounts, Uncensored Broadband Access ... Whatever the case may be, Harry, I think that you're ... Surely your English language complicator/mixmaster "knows" that. ...
    (rec.boats)
  • Re: Well, I broke down...
    ... Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ... Unlimited Access, Anonymous Accounts, Uncensored Broadband Access ... Whatever the case may be, Harry, I think that you're ... Surely your English language complicator/mixmaster "knows" that. ...
    (rec.boats)