@@ -360,12 +360,15 @@ public void enterWhen(Guard guard) throws InterruptedException {
360
360
}
361
361
final ReentrantLock lock = this .lock ;
362
362
boolean reentrant = lock .isHeldByCurrentThread ();
363
+ boolean success = false ;
363
364
lock .lockInterruptibly ();
364
365
try {
365
366
waitInterruptibly (guard , reentrant );
366
- } catch (Throwable throwable ) {
367
- lock .unlock ();
368
- throw Throwables .propagate (throwable );
367
+ success = true ;
368
+ } finally {
369
+ if (!success ) {
370
+ lock .unlock ();
371
+ }
369
372
}
370
373
}
371
374
@@ -378,12 +381,15 @@ public void enterWhenUninterruptibly(Guard guard) {
378
381
}
379
382
final ReentrantLock lock = this .lock ;
380
383
boolean reentrant = lock .isHeldByCurrentThread ();
384
+ boolean success = false ;
381
385
lock .lock ();
382
386
try {
383
387
waitUninterruptibly (guard , reentrant );
384
- } catch (Throwable throwable ) {
385
- lock .unlock ();
386
- throw Throwables .propagate (throwable );
388
+ success = true ;
389
+ } finally {
390
+ if (!success ) {
391
+ lock .unlock ();
392
+ }
387
393
}
388
394
}
389
395
@@ -404,20 +410,16 @@ public boolean enterWhen(Guard guard, long time, TimeUnit unit) throws Interrupt
404
410
if (!lock .tryLock (time , unit )) {
405
411
return false ;
406
412
}
407
- boolean satisfied ;
413
+ boolean satisfied = false ;
408
414
try {
409
415
long remainingNanos = unit .toNanos (time ) - (System .nanoTime () - startNanos );
410
416
satisfied = waitInterruptibly (guard , remainingNanos , reentrant );
411
- } catch (Throwable throwable ) {
412
- lock .unlock ();
413
- throw Throwables .propagate (throwable );
414
- }
415
- if (satisfied ) {
416
- return true ;
417
- } else {
418
- lock .unlock ();
419
- return false ;
417
+ } finally {
418
+ if (!satisfied ) {
419
+ lock .unlock ();
420
+ }
420
421
}
422
+ return satisfied ;
421
423
}
422
424
423
425
/**
@@ -450,19 +452,15 @@ public boolean enterWhenUninterruptibly(Guard guard, long time, TimeUnit unit) {
450
452
remainingNanos = (timeoutNanos - (System .nanoTime () - startNanos ));
451
453
}
452
454
}
453
- boolean satisfied ;
455
+ boolean satisfied = false ;
454
456
try {
455
457
satisfied = waitUninterruptibly (guard , remainingNanos , reentrant );
456
- } catch (Throwable throwable ) {
457
- lock .unlock ();
458
- throw Throwables .propagate (throwable );
459
- }
460
- if (satisfied ) {
461
- return true ;
462
- } else {
463
- lock .unlock ();
464
- return false ;
458
+ } finally {
459
+ if (!satisfied ) {
460
+ lock .unlock ();
461
+ }
465
462
}
463
+ return satisfied ;
466
464
} finally {
467
465
if (interruptIgnored ) {
468
466
Thread .currentThread ().interrupt ();
@@ -482,19 +480,15 @@ public boolean enterIf(Guard guard) {
482
480
}
483
481
final ReentrantLock lock = this .lock ;
484
482
lock .lock ();
485
- boolean satisfied ;
483
+ boolean satisfied = false ;
486
484
try {
487
485
satisfied = guard .isSatisfied ();
488
- } catch (Throwable throwable ) {
489
- lock .unlock ();
490
- throw Throwables .propagate (throwable );
491
- }
492
- if (satisfied ) {
493
- return true ;
494
- } else {
495
- lock .unlock ();
496
- return false ;
486
+ } finally {
487
+ if (!satisfied ) {
488
+ lock .unlock ();
489
+ }
497
490
}
491
+ return satisfied ;
498
492
}
499
493
500
494
/**
@@ -509,19 +503,15 @@ public boolean enterIfInterruptibly(Guard guard) throws InterruptedException {
509
503
}
510
504
final ReentrantLock lock = this .lock ;
511
505
lock .lockInterruptibly ();
512
- boolean satisfied ;
506
+ boolean satisfied = false ;
513
507
try {
514
508
satisfied = guard .isSatisfied ();
515
- } catch (Throwable throwable ) {
516
- lock .unlock ();
517
- throw Throwables .propagate (throwable );
518
- }
519
- if (satisfied ) {
520
- return true ;
521
- } else {
522
- lock .unlock ();
523
- return false ;
509
+ } finally {
510
+ if (!satisfied ) {
511
+ lock .unlock ();
512
+ }
524
513
}
514
+ return satisfied ;
525
515
}
526
516
527
517
/**
@@ -538,19 +528,15 @@ public boolean enterIf(Guard guard, long time, TimeUnit unit) {
538
528
if (!enter (time , unit )) {
539
529
return false ;
540
530
}
541
- boolean satisfied ;
531
+ boolean satisfied = false ;
542
532
try {
543
533
satisfied = guard .isSatisfied ();
544
- } catch (Throwable throwable ) {
545
- lock .unlock ();
546
- throw Throwables .propagate (throwable );
547
- }
548
- if (satisfied ) {
549
- return true ;
550
- } else {
551
- lock .unlock ();
552
- return false ;
534
+ } finally {
535
+ if (!satisfied ) {
536
+ lock .unlock ();
537
+ }
553
538
}
539
+ return satisfied ;
554
540
}
555
541
556
542
/**
@@ -568,19 +554,15 @@ public boolean enterIfInterruptibly(Guard guard, long time, TimeUnit unit)
568
554
if (!lock .tryLock (time , unit )) {
569
555
return false ;
570
556
}
571
- boolean satisfied ;
557
+ boolean satisfied = false ;
572
558
try {
573
559
satisfied = guard .isSatisfied ();
574
- } catch (Throwable throwable ) {
575
- lock .unlock ();
576
- throw Throwables .propagate (throwable );
577
- }
578
- if (satisfied ) {
579
- return true ;
580
- } else {
581
- lock .unlock ();
582
- return false ;
560
+ } finally {
561
+ if (!satisfied ) {
562
+ lock .unlock ();
563
+ }
583
564
}
565
+ return satisfied ;
584
566
}
585
567
586
568
/**
@@ -599,19 +581,15 @@ public boolean tryEnterIf(Guard guard) {
599
581
if (!lock .tryLock ()) {
600
582
return false ;
601
583
}
602
- boolean satisfied ;
584
+ boolean satisfied = false ;
603
585
try {
604
586
satisfied = guard .isSatisfied ();
605
- } catch (Throwable throwable ) {
606
- lock .unlock ();
607
- throw Throwables .propagate (throwable );
608
- }
609
- if (satisfied ) {
610
- return true ;
611
- } else {
612
- lock .unlock ();
613
- return false ;
587
+ } finally {
588
+ if (!satisfied ) {
589
+ lock .unlock ();
590
+ }
614
591
}
592
+ return satisfied ;
615
593
}
616
594
617
595
/**
0 commit comments