code: @SuppressWarnings("unchecked") // safe by contract of lookupToken()
    private static Token<DelegationTokenIdentifier> lookupToken(
        Credentials credentials, Text service, Text kind) throws DelegationTokenIOException {
      logger.atFine().log("Looking for token for service %s in credentials", service);
      Token<?> token = credentials.getToken(service);
      if (token != null) {
        Text tokenKind = token.getKind();
        logger.atFine().log("Found token of kind %s", tokenKind);
        if (kind.equals(tokenKind)) {
          // The OAuth implementation catches and logs here; this one throws the failure up.
          return (Token<DelegationTokenIdentifier>) token;
        }
  
        // There's a token for this service, but it's not the right DT kind
        throw DelegationTokenIOException.tokenMismatch(service, kind, tokenKind);
      }
      // A token for the service was not found
      logger.atFine().log("No token found for %s", service);
      return null;
    }
docs: Look up a token from the credentials, verify it is of the correct kind.
  
  @param credentials credentials to look up.
  @param service service name
  @param kind token kind to look for
  @return the token or null if no suitable token was found
  @throws DelegationTokenIOException wrong token kind found