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

  1. Check subfield.getPath().isEmpty() (or subfield.getPath().size() >= 2) before calling tail().
  2. Restructure the loop so tail() is only invoked while more than one path element remains.
  3. 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

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


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/1da61d94666cd95d. Report an issue: GitHub.