{"record":{"id":"354a7e371c22095e","repo":"prestodb/presto","slug":"pattern-may-be-specified-only-if-location-is-a-dir","errorCode":null,"errorMessage":"pattern may be specified only if location is a directory","messagePattern":"pattern may be specified only if location is a directory","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-local-file/src/main/java/com/facebook/presto/localfile/DataLocation.java","lineNumber":57,"sourceCode":"    private final Optional<String> pattern;\n\n    @SuppressWarnings(\"ResultOfMethodCallIgnored\")\n    @JsonCreator\n    public DataLocation(\n            @JsonProperty(\"location\") String location,\n            @JsonProperty(\"pattern\") Optional<String> pattern)\n    {\n        requireNonNull(location, \"location is null\");\n        requireNonNull(pattern, \"pattern is null\");\n\n        File file = new File(location);\n        if (!file.exists() && pattern.isPresent()) {\n            file.mkdirs();\n        }\n\n        checkArgument(file.exists(), \"location does not exist\");\n        if (pattern.isPresent() && !file.isDirectory()) {\n            throw new IllegalArgumentException(\"pattern may be specified only if location is a directory\");\n        }\n\n        this.location = file;\n        this.pattern = (!pattern.isPresent() && file.isDirectory()) ? Optional.of(\"*\") : pattern;\n    }\n\n    @JsonProperty\n    public File getLocation()\n    {\n        return location;\n    }\n\n    @JsonProperty\n    public Optional<String> getPattern()\n    {\n        return pattern;\n    }\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-local-file/src/main/java/com/facebook/presto/localfile/DataLocation.java#L39-L75","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before (catalog properties)\nlocalfile.location=/data/events.csv\nlocalfile.pattern=*.csv\n\n// after\nlocalfile.location=/data/events\nlocalfile.pattern=*.csv","handlingStrategy":"validation","validationCode":"File f = new File(location);\nif (pattern != null && !f.isDirectory()) {\n    throw new IllegalArgumentException(\"pattern requires a directory location\");\n}","typeGuard":"boolean patternNeedsDirectory(Optional<String> pattern, File f) { return pattern.isPresent() && !f.isDirectory(); }","tryCatchPattern":"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; } }","preventionTips":["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."],"tags":["configuration","validation","localfile"],"backgroundTag":"invalid-config-value","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"}