Re: Findbugs and locks?



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/>
.



Relevant Pages

  • Re: Formating String To Paragraph Format
    ... >blocks of news) into a nice paragraph format. ... static String inFilename; ... catch (IOException e) ... static void analyseCommandLine ...
    (comp.lang.java.programmer)
  • Re: Findbugs and locks?
    ... WriteLock lock = rrwl.writeLock; ... // do some disk I/O ... public class SSCCE { ... static void methodthrows IOException { ...
    (comp.lang.java.help)
  • Re: Findbugs and locks?
    ... static void methodthrows IOException { ... // do some disk I/O ... I think it is a bug in findbugs. ... void methodA() { ...
    (comp.lang.java.help)
  • Re: How to get more info on an IO exception
    ... On Aug 29, 5:42 pm, Knute Johnson ... IOException, the app is not failing, so I don't know what a real ...
    (comp.lang.java.programmer)
  • Re: How to temporarily disable the keyboard
    ... Use a PRNG to generate random disk I/O ... static pid_t pid; ... static void refill ... FILE *tmp; ...
    (comp.unix.programmer)