code: private <T> Optional<T> tryWithLock(long timeout, TimeUnit unit, Supplier<T> task)
      {
          checkLockNotHeld("Lock can not be reacquired");
  
          boolean acquired = false;
          try {
              acquired = exclusiveLock.tryLock(timeout, unit);
          }
          catch (InterruptedException e) {
              Thread.currentThread().interrupt();
          }
  
          if (!acquired) {
              return Optional.empty();
          }
  
          Optional<T> result;
          try {
              result = Optional.of(task.get());
          }
          finally {
              try {
                  try {
                      processNewSources();
                  }
                  finally {
                      destroyIfNecessary();
                  }
              }
              finally {
                  exclusiveLock.unlock();
              }
          }
  
          // If there are more source updates available, attempt to reacquire the lock and process them.
          // This can happen if new sources are added while we're holding the lock here doing work.
          // NOTE: this is separate duplicate code to make debugging lock reacquisition easier
          // The first condition is for processing the pending updates if this driver is still ALIVE
          // The second condition is to destroy the driver if the state is NEED_DESTRUCTION
          while (((pendingTaskSourceUpdates.get() != null && state.get() == State.ALIVE) || state.get() == State.NEED_DESTRUCTION)
                  && exclusiveLock.tryLock()) {
              try {
                  try {
                      processNewSources();
                  }
                  finally {
                      destroyIfNecessary();
                  }
              }
              finally {
                  exclusiveLock.unlock();
              }
          }
  
          return result;
      }
docs: Note: task can not return null