prestodb/presto · error · java.lang.IllegalStateException
path is empty
Error message
path is empty
What it means
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.
Source
Thrown at presto-common/src/main/java/com/facebook/presto/common/Subfield.java:328
}
public boolean isPrefix(Subfield other)
{
if (!other.name.equals(name)) {
return false;
}
if (path.size() < other.path.size()) {
return Objects.equals(path, other.path.subList(0, path.size()));
}
return false;
}
public Subfield tail(String name)
{
if (path.isEmpty()) {
throw new IllegalStateException("path is empty");
}
return new Subfield(name, path.subList(1, path.size()));
}
@JsonValue
public String serialize()
{
return name + path.stream()
.map(PathElement::toString)
.collect(Collectors.joining());
}
@Override
public String toString()
{
return serialize();
}View on GitHub (pinned to 55bb57d202)
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().
Example fix
// before
Subfield result = subfield.tail(prefixName); // IllegalStateException if path empty
// after
if (subfield.getPath().isEmpty()) {
return subfield; // or handle explicitly
}
Subfield result = subfield.tail(prefixName); Defensive patterns
Strategy: type-guard
Validate before calling
if (subfield.getPath().isEmpty()) {
throw new IllegalStateException("cannot take tail of subfield with empty path: " + subfield);
}
Subfield tailed = subfield.tail(newRoot); Type guard
boolean hasTail(Subfield subfield) {
return !subfield.getPath().isEmpty();
} Try / catch
try {
Subfield tailed = subfield.tail(name);
} catch (IllegalStateException e) {
// empty path: keep original subfield or handle explicitly
tailed = subfield;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid field position selection after nulls removed: " + se
- Map key is null at position: " + position
- Current entry must be closed before a null can be written
- Current entry must be closed before a null can be written
- Current entry must be closed before the block can be built
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/1da61d94666cd95d.
Report an issue: GitHub.