apache/hadoop · error · IllegalArgumentException

secretProvider cannot be NULL

Error message

secretProvider cannot be NULL

What it means

Signer computes and verifies the HMAC-SHA256 signature appended to authentication cookie values, delegating secret management to a SignerSecretProvider. The constructor requires a non-null, already-initialized provider; passing null throws IllegalArgumentException('secretProvider cannot be NULL') to fail fast rather than NPE later during signing.

Source

Thrown at hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/util/Signer.java:42

/**
 * Signs strings and verifies signed strings using a SHA digest.
 */
public class Signer {
  private static final String SIGNATURE = "&s=";
  private static final String SIGNING_ALGORITHM = "HmacSHA256";

  private SignerSecretProvider secretProvider;

  /**
   * Creates a Signer instance using the specified SignerSecretProvider.  The
   * SignerSecretProvider should already be initialized.
   *
   * @param secretProvider The SignerSecretProvider to use
   */
  public Signer(SignerSecretProvider secretProvider) {
    if (secretProvider == null) {
      throw new IllegalArgumentException("secretProvider cannot be NULL");
    }
    this.secretProvider = secretProvider;
  }

  /**
   * Returns a signed string.
   *
   * @param str string to sign.
   *
   * @return the signed string.
   */
  public synchronized String sign(String str) {
    if (str == null || str.length() == 0) {
      throw new IllegalArgumentException("NULL or empty string to sign");
    }
    byte[] secret = secretProvider.getCurrentSecret();
    String signature = computeSignature(secret, str);
    return str + SIGNATURE + signature;

View on GitHub (pinned to 2add963021)

Solutions

  1. Initialize a concrete SignerSecretProvider (RandomSignerSecretProvider, FileSignerSecretProvider, ZKSignerSecretProvider) first and pass that instance
  2. Check provider initialization for swallowed exceptions so the variable is never silently null
  3. For tests, use a provider with a fixed secret to keep behavior deterministic

Example fix

// before
Signer signer = new Signer(null);

// after
SignerSecretProvider provider = new RandomSignerSecretProvider();
provider.init(new Properties(), null, -1);
Signer signer = new Signer(provider);
Defensive patterns

Strategy: type-guard

Validate before calling

if (secretProvider == null) throw new IllegalStateException("SignerSecretProvider not initialized — check init() for swallowed errors");

Type guard

static boolean isUsableProvider(SignerSecretProvider p) {
  return p != null && p.getCurrentSecret() != null && p.getCurrentSecret().length > 0;
}

Try / catch

not needed once construction is guarded — fix the wiring so the provider is initialized before new Signer(provider)

Prevention

When it happens

Trigger: new Signer(null) — typically because the SignerSecretProvider was constructed/initialized conditionally and the variable stayed null (config branch not taken, initialization swallowed an error).

Common situations: Custom authentication filters wiring their own provider chain; refactoring that moves provider init after Signer construction; tests instantiating Signer without setting up a provider.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/28fd339a22b0d229. Report an issue: GitHub.