Code RoomLock not released on exception
MediumPrep Room Coding #1866

Lock not released on exception

Code reviewConcurrencyMid–Senior~25 min

Review this Java method using an explicit ReentrantLock.

What concurrency-relevant failure does this have?

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 25 min
Mark a line and say what kind of problem it is.0 findings
1class Ledger {
2 private final ReentrantLock lock = new ReentrantLock();
3 private long total;
4 
5 long applyAndRead(long delta) {
6 lock.lock();
7 total += delta;
8 long snapshot = expensiveAudit(total); // (1) may throw
9 lock.unlock();
10 return snapshot;
11 }
12}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.