Re: Findbugs and locks?



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) {

}

}
.



Relevant Pages

  • RE: A button question!
    ... (as opposed to locking them by default then unlocking them if they are new) ... Private Sub NewRec_Click ... "Andy Hull" wrote: ... "lock" the fields. ...
    (microsoft.public.access.forms)
  • Re: Snow Leopard Time Machine wont stay locked
    ... unlocking. ... How does one make the lock "stick"? ... When I go to the Time Machine pref pane, ... Security pref panes setting are locked, ...
    (comp.sys.mac.apps)
  • Re: threaded queue - and cream cheese
    ... the queue is empty and release it when adding to the queue. ... unlocking an unlocked lock, and occaisionally there will be a message ... Threading, and in particular thread synchronization, is not the ...
    (comp.sys.mac.programmer.help)
  • Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock()
    ... you only need to do the reverse unlock ... if you do it after unlocking the outer lock? ...
    (Linux-Kernel)
  • A scoped lock/unlock implementation in C++.
    ... A recent thread about scope-based locking and scope-based unlocking ... Define a "scoped lock" as an object that acquires a lock on a mutex at ... A locked region is an area where the mutex is normally ...
    (comp.programming.threads)