{"record":{"id":"2633b85472100da1","repo":"redis/jedis","slug":"path-cannot-be-empty","errorCode":null,"errorMessage":"Path cannot be empty.","messagePattern":"Path cannot be empty\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/json/Path2.java","lineNumber":17,"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\n  public static Path2 of(final String path) {\n    return new Path2(path);\n  }","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/json/Path2.java#L1-L35","documentation":"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 '.').","triggerScenarios":"Calling new Path2(\"\") or passing a trimmed-away/blank path variable into the constructor.","commonSituations":"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 \"\".","solutions":["Pass a non-empty path such as \"$\" (root), \"$.field\", or \".field\"","Guard the input with isEmpty() before constructing Path2","Use Path2.ROOT_PATH instead of new Path2(\"\") when you mean the root"],"exampleFix":"// before\nPath2 p = new Path2(pathStr.trim()); // empty if blank\n// after\nif (pathStr == null || pathStr.trim().isEmpty()) { pathStr = \"$\"; }\nPath2 p = new Path2(pathStr.trim());","handlingStrategy":"validation","validationCode":"if (pathStr == null || pathStr.trim().isEmpty()) { pathStr = \"$\"; }\nPath2 p = new Path2(pathStr);","typeGuard":"boolean isValidPath(String s) { return s != null && !s.trim().isEmpty(); }","tryCatchPattern":"try { Path2 p = new Path2(s); } catch (IllegalArgumentException e) { p = Path2.ROOT_PATH; }","preventionTips":["Never construct paths by stripping leading '$'/'.' characters","Trim and default blank config values to \"$\"","Unit-test path construction with empty-string inputs"],"tags":["json","path","empty-argument","validation"],"backgroundTag":"empty-required-field","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"}