@@ -384,8 +384,9 @@ boolean acquirePermitFair(final long timeout, final TimeUnit unit) throws MongoI
384
384
throw new MongoInterruptedException (null , e );
385
385
}
386
386
try {
387
- while (permits == 0 ) {
388
- throwIfClosedOrPaused ();
387
+ while (permits == 0
388
+ // the absence of short-circuiting is of importance
389
+ & !throwIfClosedOrPaused ()) {
389
390
try {
390
391
if (timeout < 0 || remainingNanos == Long .MAX_VALUE ) {
391
392
permitAvailableOrClosedOrPausedCondition .await ();
@@ -399,7 +400,6 @@ boolean acquirePermitFair(final long timeout, final TimeUnit unit) throws MongoI
399
400
}
400
401
}
401
402
assertTrue (permits > 0 );
402
- throwIfClosedOrPaused ();
403
403
//noinspection NonAtomicOperationOnVolatileField
404
404
permits --;
405
405
return true ;
@@ -465,12 +465,15 @@ boolean close() {
465
465
}
466
466
467
467
/**
468
+ * @return {@code false} which means that the method did not throw.
469
+ * The method returns to allow using it conveniently as part of a condition check when waiting on a {@link Condition}.
470
+ * Short-circuiting operators {@code &&} and {@code ||} must not be used with this method to ensure that it is called.
468
471
* @throws MongoServerUnavailableException If and only if {@linkplain #close() closed}.
469
472
* @throws MongoException If and only if {@linkplain #pause(Supplier) paused}
470
473
* and not {@linkplain #close() closed}. The exception is specified via the {@link #pause(Supplier)} method
471
474
* and may be a subtype of {@link MongoException}.
472
475
*/
473
- void throwIfClosedOrPaused () {
476
+ boolean throwIfClosedOrPaused () {
474
477
if (closed ) {
475
478
throw poolClosedExceptionSupplier .get ();
476
479
}
@@ -484,6 +487,7 @@ void throwIfClosedOrPaused() {
484
487
lock .readLock ().unlock ();
485
488
}
486
489
}
490
+ return false ;
487
491
}
488
492
489
493
boolean closed () {
0 commit comments