apache/hadoop · error · IllegalArgumentException

{name} cannot be empty

Error message

{name} cannot be empty

What it means

Check.notEmpty(str, name) throws IllegalArgumentException('<name> cannot be empty') on its second branch: the string is non-null but has length 0. It guards string parameters of the httpfs service API (e.g. the 'user' argument of FileSystemAccess.execute / createFileSystemInternal), so an empty string is rejected just like null.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/util/Check.java:85

    return list;
  }

  /**
   * Verifies a string is not NULL and not emtpy
   *
   * @param str the variable to check.
   * @param name the name to use in the exception message.
   *
   * @return the variable.
   *
   * @throws IllegalArgumentException if the variable is NULL or empty.
   */
  public static String notEmpty(String str, String name) {
    if (str == null) {
      throw new IllegalArgumentException(name + " cannot be null");
    }
    if (str.length() == 0) {
      throw new IllegalArgumentException(name + " cannot be empty");
    }
    return str;
  }

  /**
   * Verifies a string list is not NULL and not emtpy
   *
   * @param list the list to check.
   * @param name the name to use in the exception message.
   *
   * @return the variable.
   *
   * @throws IllegalArgumentException if the string list has NULL or empty
   * elements.
   */
  public static List<String> notEmptyElements(List<String> list, String name) {
    notNull(list, name);
    for (int i = 0; i < list.size(); i++) {

View on GitHub (pinned to 2add963021)

Solutions

  1. The message names the empty parameter - fix the caller to supply a real value
  2. Trim and validate input at the request boundary: reject null, empty, and whitespace-only strings with a 4xx before invoking the service
  3. Log the offending parameter at the boundary so bad requests are diagnosable without stack traces
  4. Add tests for the empty-string input path

Example fix

// before
String user = StringUtils.trimToEmpty(req.getParameter("doas")); // '' for absent param
fsAccess.execute(user, conf, executor); // IllegalArgumentException: user cannot be empty

// after
String user = StringUtils.trimToNull(req.getParameter("doas"));
if (user == null) {
  resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "doas parameter required");
  return;
}
fsAccess.execute(user, conf, executor);
Defensive patterns

Strategy: validation

Validate before calling

import org.apache.commons.lang3.StringUtils;

String user = req.getParameter("doas");
if (StringUtils.isBlank(user)) {
  resp.sendError(javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST, "doas parameter must be non-empty");
  return;
}
fsAccess.execute(user.trim(), conf, executor);

Type guard

static boolean isNonEmptyString(String s) {
  return s != null && !s.trim().isEmpty();
}

Try / catch

try {
  fsAccess.execute(user, conf, executor);
} catch (IllegalArgumentException ex) {
  if (ex.getMessage().endsWith("cannot be empty")) {
    // empty string argument - client input problem, map to 400 and do not retry
    resp.sendError(400, ex.getMessage());
    return;
  }
  throw ex;
}

Prevention

When it happens

Trigger: Calling a guarded API with "", e.g. execute("", conf, executor) or createFileSystem("", conf) - the null branch is skipped because the reference is non-null, then str.length()==0 triggers this throw.

Common situations: Frontend sends an empty user/doAs parameter that is trimmed and forwarded; string trimming logic reduces whitespace-only input to "" before the call; configuration-derived usernames defaulting to an empty string.

Related errors


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