prestodb/presto · error · IllegalArgumentException
pattern may be specified only if location is a directory
Error message
pattern may be specified only if location is a directory
What it means
The DataLocation constructor validates that a 'pattern' (glob for file discovery) may only be supplied when the configured location path is an existing directory. If the location resolves to a regular file (or non-directory) and a pattern was provided, IllegalArgumentException is thrown.
Source
Thrown at presto-local-file/src/main/java/com/facebook/presto/localfile/DataLocation.java:57
private final Optional<String> pattern;
@SuppressWarnings("ResultOfMethodCallIgnored")
@JsonCreator
public DataLocation(
@JsonProperty("location") String location,
@JsonProperty("pattern") Optional<String> pattern)
{
requireNonNull(location, "location is null");
requireNonNull(pattern, "pattern is null");
File file = new File(location);
if (!file.exists() && pattern.isPresent()) {
file.mkdirs();
}
checkArgument(file.exists(), "location does not exist");
if (pattern.isPresent() && !file.isDirectory()) {
throw new IllegalArgumentException("pattern may be specified only if location is a directory");
}
this.location = file;
this.pattern = (!pattern.isPresent() && file.isDirectory()) ? Optional.of("*") : pattern;
}
@JsonProperty
public File getLocation()
{
return location;
}
@JsonProperty
public Optional<String> getPattern()
{
return pattern;
}
View on GitHub (pinned to 55bb57d202)
Solutions
- Point localfile.location at a directory, keeping the pattern.
- Remove the localfile.pattern property if the location is meant to be a single file.
- Verify the location path exists and is a directory before startup (constructor already mkdirs when absent and pattern is present).
Example fix
// before (catalog properties) localfile.location=/data/events.csv localfile.pattern=*.csv // after localfile.location=/data/events localfile.pattern=*.csv
Defensive patterns
Strategy: validation
Validate before calling
File f = new File(location);
if (pattern != null && !f.isDirectory()) {
throw new IllegalArgumentException("pattern requires a directory location");
} Type guard
boolean patternNeedsDirectory(Optional<String> pattern, File f) { return pattern.isPresent() && !f.isDirectory(); } Try / catch
try { DataLocation loc = new DataLocation(config.getLocation(), config.getPattern()); } catch (IllegalArgumentException e) { if (e.getMessage().contains("pattern may be specified only if location is a directory")) { fixCatalogProperties(); } else { throw e; } } Prevention
- Keep location/pattern pairs consistent: pattern only with directory locations.
- Validate catalog properties before deploying the connector.
- When switching a catalog from single-file to directory mode, update both properties together.
When it happens
Trigger: Constructing DataLocation with localfile.location pointing at a file while localfile.pattern is set in the connector config, or programmatically passing a pattern for a file-based location.
Common situations: Misconfigured localfile catalog: location set to a single file but a glob pattern left over from a previous directory-based config; copy-pasting properties between catalogs.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Invalid value [%s]. Valid values: %s
- INVALID_SESSION_PROPERTY
- iceberg.target-max-file-size must be at least 1 byte
- INVALID_SESSION_PROPERTY
- Invalid Kafka Offset start/end pair: %s - %s
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/354a7e371c22095e.
Report an issue: GitHub.