redis/jedis · error · IllegalArgumentException

Path cannot be empty.

Error message

Path cannot be empty.

What it means

Path2's constructor throws IllegalArgumentException when the path string is empty. RedisJSON paths must be at least one character; empty strings cannot form a valid path (root is "$", dot-paths start with '.').

Solutions

  1. Pass a non-empty path such as "$" (root), "$.field", or ".field"
  2. Guard the input with isEmpty() before constructing Path2
  3. Use Path2.ROOT_PATH instead of new Path2("") when you mean the root

Example fix

// before
Path2 p = new Path2(pathStr.trim()); // empty if blank
// after
if (pathStr == null || pathStr.trim().isEmpty()) { pathStr = "$"; }
Path2 p = new Path2(pathStr.trim());
Defensive patterns

Strategy: validation

Validate before calling

if (pathStr == null || pathStr.trim().isEmpty()) { pathStr = "$"; }
Path2 p = new Path2(pathStr);

Type guard

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

Try / catch

try { Path2 p = new Path2(s); } catch (IllegalArgumentException e) { p = Path2.ROOT_PATH; }

Prevention

When it happens

Trigger: Calling new Path2("") or passing a trimmed-away/blank path variable into the constructor.

Common situations: Path built by concatenation that ended up empty; optional config key present but set to empty string; stripping a leading '$'/'.' from an existing path leaves "".

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/2633b85472100da1. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/json/Path2.java:17

package redis.clients.jedis.json;

/**
 * Path is a RedisJSON v2 path, representing a valid path or a multi-path into an object.
 */
public class Path2 {

  public static final Path2 ROOT_PATH = new Path2("$");

  private final String str;

  public Path2(final String str) {
    if (str == null) {
      throw new NullPointerException("Path cannot be null.");
    }
    if (str.isEmpty()) {
      throw new IllegalArgumentException("Path cannot be empty.");
    }
    if (str.charAt(0) == '$') {
      this.str = str;
    } else if (str.charAt(0) == '.') {
      this.str = '$' + str;
    } else {
      this.str = "$." + str;
    }
  }

  @Override
  public String toString() {
    return str;
  }

  public static Path2 of(final String path) {
    return new Path2(path);
  }

View on GitHub (pinned to 6dac31d4c2)