docs: @SuppressWarnings("unchecked")
      protected @Nonnull <T> Collection<BeanDefinition<T>>  findBeanCandidates(@Nonnull Class<T> beanType, @Nullable BeanDefinition<?> filter) {
          ArgumentUtils.requireNonNull("beanType", beanType);
  
          if (LOG.isDebugEnabled()) {
              LOG.debug("Finding candidate beans for type: {}", beanType);
          }
          // first traverse component definition classes and load candidates
  
          Collection<BeanDefinitionReference> beanDefinitionsClasses;
  
          if (indexedTypes.contains(beanType)) {
              beanDefinitionsClasses = beanIndex.get(beanType);
              if (beanDefinitionsClasses == null) {
                  beanDefinitionsClasses = Collections.emptyList();
              }
          } else {
              beanDefinitionsClasses = this.beanDefinitionsClasses;
          }
  
          if (!beanDefinitionsClasses.isEmpty()) {
  
              Stream<BeanDefinition<T>> candidateStream = beanDefinitionsClasses
                      .stream()
                      .filter(reference -> {
                          if (reference.isPresent()) {
                              Class<?> candidateType = reference.getBeanType();
                              final boolean isCandidate = candidateType != null && (beanType.isAssignableFrom(candidateType) || beanType == candidateType);
                              return isCandidate && reference.isEnabled(this);
                          }
                          return false;
                      })
                      .map(ref -> {
                          BeanDefinition<T> loadedBean;
                          try {
                              loadedBean = ref.load(this);
                          } catch (Throwable e) {
                              throw new BeanContextException("Error loading bean [" + ref.getName() + "]: " + e.getMessage(), e);
                          }
                          return loadedBean;
                      });
  
              if (filter != null) {
                  candidateStream = candidateStream.filter(candidate -> !candidate.equals(filter));
              }
              Set<BeanDefinition<T>> candidates = candidateStream
                      .filter(candidate -> candidate.isEnabled(this))
                      .collect(Collectors.toSet());
  
              if (!candidates.isEmpty()) {
                  filterReplacedBeans(candidates);
              }
  
              if (LOG.isDebugEnabled()) {
                  LOG.debug("Resolved bean candidates {} for type: {}", candidates, beanType);
              }
              return candidates;
          } else {
              if (LOG.isDebugEnabled()) {
                  LOG.debug("No bean candidates found for type: {}", beanType);
              }
              return Collections.emptySet();
          }
      }