{"record":{"id":"6ea2198a62ae7d65","repo":"apache/beam","slug":"need-to-set-the-filepattern-of-a-tfrecordio-read-transform","errorCode":null,"errorMessage":"Need to set the filepattern of a TFRecordIO.Read transform","messagePattern":"Need to set the filepattern of a TFRecordIO\\.Read transform","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/io/TFRecordIO.java","lineNumber":183,"sourceCode":"      return withCompression(compressionType.canonical);\n    }\n\n    /**\n     * Returns a transform for reading TFRecord files that decompresses all input files using the\n     * specified compression type.\n     *\n     * <p>If no compression type is specified, the default is {@link Compression#AUTO}. In this\n     * mode, the compression type of the file is determined by its extension via {@link\n     * Compression#detect(String)}.\n     */\n    public Read withCompression(Compression compression) {\n      return toBuilder().setCompression(compression).build();\n    }\n\n    @Override\n    public PCollection<byte[]> expand(PBegin input) {\n      if (getFilepattern() == null) {\n        throw new IllegalStateException(\n            \"Need to set the filepattern of a TFRecordIO.Read transform\");\n      }\n\n      if (getValidate()) {\n        checkState(getFilepattern().isAccessible(), \"Cannot validate with a RVP.\");\n        try {\n          MatchResult matches = FileSystems.match(getFilepattern().get());\n          checkState(\n              !matches.metadata().isEmpty(),\n              \"Unable to find any files matching %s\",\n              getFilepattern().get());\n        } catch (IOException e) {\n          throw new IllegalStateException(\n              String.format(\"Failed to validate %s\", getFilepattern().get()), e);\n        }\n      }\n\n      return input.apply(\"Read\", org.apache.beam.sdk.io.Read.from(getSource()));","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/io/TFRecordIO.java#L165-L201","documentation":"TFRecordIO.Read.expand() throws this IllegalStateException when the transform's filepattern was never set. TFRecordIO needs a file glob or path to read from; without it there is nothing to configure the source with, so validation fails fast before pipeline submission.","triggerScenarios":"Applying TFRecordIO.read() without calling .from(\"gs://bucket/path/*.tfrecord\") on the builder.","commonSituations":"Building the transform programmatically where the from() call was skipped; passing a null variable holding the path; conditional code paths that never set the filepattern.","solutions":["Call .from(\"path/or/glob/*.tfrecords\") on the TFRecordIO.read() builder before applying the transform.","Check that the variable holding the filepattern is non-null at transform construction time."],"exampleFix":"// before\npipeline.apply(TFRecordIO.read());\n\n// after\npipeline.apply(TFRecordIO.read().from(\"gs://my-bucket/data/*.tfrecord\"));","handlingStrategy":"validation","validationCode":"if (filePattern == null || filePattern.isEmpty()) {\n  throw new IllegalArgumentException(\"TFRecordIO filepattern must be set via .from(...)\");\n}\nTFRecordIO.read().from(filePattern);","typeGuard":null,"tryCatchPattern":"try { pipeline.apply(TFRecordIO.read().from(filePattern)); } catch (IllegalStateException e) { if (e.getMessage().contains(\"filepattern\")) { log.error(\"Missing TFRecordIO filepattern\"); } throw e; }","preventionTips":["Centralize TFRecordIO.read() construction so .from() is always called.","Fail fast in configuration loading when the input path is absent."],"tags":["java","beam","tfrecord","io","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}