{"record":{"id":"1da61d94666cd95d","repo":"prestodb/presto","slug":"path-is-empty","errorCode":null,"errorMessage":"path is empty","messagePattern":"path is empty","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/Subfield.java","lineNumber":328,"sourceCode":"    }\n\n    public boolean isPrefix(Subfield other)\n    {\n        if (!other.name.equals(name)) {\n            return false;\n        }\n\n        if (path.size() < other.path.size()) {\n            return Objects.equals(path, other.path.subList(0, path.size()));\n        }\n\n        return false;\n    }\n\n    public Subfield tail(String name)\n    {\n        if (path.isEmpty()) {\n            throw new IllegalStateException(\"path is empty\");\n        }\n\n        return new Subfield(name, path.subList(1, path.size()));\n    }\n\n    @JsonValue\n    public String serialize()\n    {\n        return name + path.stream()\n                .map(PathElement::toString)\n                .collect(Collectors.joining());\n    }\n\n    @Override\n    public String toString()\n    {\n        return serialize();\n    }","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/Subfield.java#L310-L346","documentation":"Subfield.tail(name) returns a new Subfield whose path drops the first path element, re-anchoring it under the given name. It throws this IllegalStateException when the subfield's path is empty, because there is no tail to take — the operation is undefined for a Subfield with no path elements.","triggerScenarios":"Calling subfield.tail(name) on a Subfield constructed with an empty path (new Subfield(name, ImmutableList.of()) or similar) — e.g. iterating and stripping path elements until the path is exhausted, then calling tail again.","commonSituations":"Predicate pushdown code (toCoercingFilter) that walks subfield paths element by element; loops that don't check path.isEmpty() before the final tail(); malformed subfield strings that parse to an empty path.","solutions":["Check subfield.getPath().isEmpty() (or subfield.getPath().size() >= 2) before calling tail().","Restructure the loop so tail() is only invoked while more than one path element remains.","If an empty path is valid input, construct/return the Subfield directly instead of deriving it via tail()."],"exampleFix":"// before\nSubfield result = subfield.tail(prefixName); // IllegalStateException if path empty\n// after\nif (subfield.getPath().isEmpty()) {\n    return subfield; // or handle explicitly\n}\nSubfield result = subfield.tail(prefixName);","handlingStrategy":"type-guard","validationCode":"if (subfield.getPath().isEmpty()) {\n    throw new IllegalStateException(\"cannot take tail of subfield with empty path: \" + subfield);\n}\nSubfield tailed = subfield.tail(newRoot);","typeGuard":"boolean hasTail(Subfield subfield) {\n    return !subfield.getPath().isEmpty();\n}","tryCatchPattern":"try {\n    Subfield tailed = subfield.tail(name);\n} catch (IllegalStateException e) {\n    // empty path: keep original subfield or handle explicitly\n    tailed = subfield;\n}","preventionTips":["Check path size before each tail() call in traversal loops.","Treat single-element paths as terminal — do not call tail() on them.","Validate subfields parsed from user strings for non-empty paths.","Write a unit test covering an empty-path Subfield."],"tags":["presto","subfield","illegal-state","empty-path"],"backgroundTag":"empty-path-illegal-state","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}