{"record":{"id":"bb038b6596bc0852","repo":"redis/jedis","slug":"path-cannot-be-null","errorCode":null,"errorMessage":"Path cannot be null.","messagePattern":"Path cannot be null\\.","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/json/Path2.java","lineNumber":14,"sourceCode":"package redis.clients.jedis.json;\n\n/**\n * Path is a RedisJSON v2 path, representing a valid path or a multi-path into an object.\n */\npublic class Path2 {\n\n  public static final Path2 ROOT_PATH = new Path2(\"$\");\n\n  private final String str;\n\n  public Path2(final String str) {\n    if (str == null) {\n      throw new NullPointerException(\"Path cannot be null.\");\n    }\n    if (str.isEmpty()) {\n      throw new IllegalArgumentException(\"Path cannot be empty.\");\n    }\n    if (str.charAt(0) == '$') {\n      this.str = str;\n    } else if (str.charAt(0) == '.') {\n      this.str = '$' + str;\n    } else {\n      this.str = \"$.\" + str;\n    }\n  }\n\n  @Override\n  public String toString() {\n    return str;\n  }\n","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/json/Path2.java#L1-L32","documentation":"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.","triggerScenarios":"Calling new Path2(null), or Path2.fromJsonPath-style helpers/config passing a null path variable down to the constructor.","commonSituations":"Path loaded from optional config or a null default; missing key in a properties/JSON config map used to build the path.","solutions":["Pass a valid non-null path string, e.g. new Path2(\"$.myField\") or use Path2.ROOT_PATH for the root","Check where the path string comes from and give it a sensible default (\"$\")","Validate/require the path in your configuration before constructing Path2"],"exampleFix":"// before\nPath2 p = new Path2(config.get(\"path\")); // may be null\n// after\nString s = config.getOrDefault(\"path\", \"$\");\nPath2 p = new Path2(s);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(pathStr, \"Path cannot be null.\");\nPath2 p = new Path2(pathStr);","typeGuard":"boolean hasPath(String s) { return s != null && !s.isEmpty(); }","tryCatchPattern":"try { Path2 p = new Path2(s); } catch (NullPointerException e) { p = Path2.ROOT_PATH; }","preventionTips":["Default missing paths to \"$\" (root)","Validate config maps for the path key before use","Prefer Path2.ROOT_PATH constant for root paths"],"tags":["json","path","null-argument","validation"],"backgroundTag":"null-argument","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}