redis/jedis · error · NullPointerException

Path cannot be null.

Error message

Path cannot be null.

What it means

Guard in the Path2 constructor: a null path string is rejected with NPE before any JSON command is built. Path2 represents RedisJSON v2 paths, and a null path has no meaning — callers should pass '$', '$.field', or use Path2.ROOT_PATH.

Solutions

  1. Pass a valid non-null path string, e.g. new Path2("$.myField") or use Path2.ROOT_PATH for the root
  2. Check where the path string comes from and give it a sensible default ("$")
  3. Validate/require the path in your configuration before constructing Path2

Example fix

// before
Path2 p = new Path2(config.get("path")); // may be null
// after
String s = config.getOrDefault("path", "$");
Path2 p = new Path2(s);
Defensive patterns

Strategy: validation

Validate before calling

Objects.requireNonNull(pathStr, "Path cannot be null.");
Path2 p = new Path2(pathStr);

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Calling new Path2(null), or Path2.fromJsonPath-style helpers/config passing a null path variable down to the constructor.

Common situations: Path loaded from optional config or a null default; missing key in a properties/JSON config map used to build the path.

Related errors


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

Appendix: source

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

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;
  }

View on GitHub (pinned to 6dac31d4c2)