{"record":{"id":"1199462119bffc9a","repo":"apache/hadoop","slug":"file-or-stream-must-be-specified","errorCode":null,"errorMessage":"file or stream must be specified","messagePattern":"file or stream must be specified","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/SequenceFile.java","lineNumber":1098,"sourceCode":"        Options.getOption(ProgressableOption.class, opts);\n      FileOption fileOption = Options.getOption(FileOption.class, opts);\n      AppendIfExistsOption appendIfExistsOption = Options.getOption(\n          AppendIfExistsOption.class, opts);\n      FileSystemOption fsOption = Options.getOption(FileSystemOption.class, opts);\n      StreamOption streamOption = Options.getOption(StreamOption.class, opts);\n      KeyClassOption keyClassOption = \n        Options.getOption(KeyClassOption.class, opts);\n      ValueClassOption valueClassOption = \n        Options.getOption(ValueClassOption.class, opts);\n      MetadataOption metadataOption = \n        Options.getOption(MetadataOption.class, opts);\n      CompressionOption compressionTypeOption =\n        Options.getOption(CompressionOption.class, opts);\n      SyncIntervalOption syncIntervalOption =\n          Options.getOption(SyncIntervalOption.class, opts);\n      // check consistency of options\n      if ((fileOption == null) == (streamOption == null)) {\n        throw new IllegalArgumentException(\"file or stream must be specified\");\n      }\n      if (fileOption == null && (blockSizeOption != null ||\n                                 bufferSizeOption != null ||\n                                 replicationOption != null ||\n                                 progressOption != null)) {\n        throw new IllegalArgumentException(\"file modifier options not \" +\n                                           \"compatible with stream\");\n      }\n\n      FSDataOutputStream out;\n      boolean ownStream = fileOption != null;\n      if (ownStream) {\n        Path p = fileOption.getValue();\n        FileSystem fs;\n        if (fsOption != null) {\n          fs = fsOption.getValue();\n        } else {\n          fs = p.getFileSystem(conf);","sourceCodeStart":1080,"sourceCodeEnd":1116,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/SequenceFile.java#L1080-L1116","documentation":"SequenceFile.createWriter(conf, Option...) requires exactly one destination option: either Writer.file(path) or Writer.stream(FSDataOutputStream). The constructor checks (fileOption == null) == (streamOption == null) and throws this IllegalArgumentException when both are present or both are absent, failing fast before any output is opened.","triggerScenarios":"Passing both Writer.file(p) and Writer.stream(out) in the same option list; passing only key/value/compression options with no destination at all.","commonSituations":"Migrating legacy SequenceFile.createWriter(Path, ...) call sites onto the Options API; copy-pasted option lists where a stream option survived next to a new file option; factory code that assembles options dynamically and ends up with none.","solutions":["Pass exactly one of Writer.file(path) or Writer.stream(out)","If the target is a path, remove the stream option (and note the writer will open/close the file itself)","If the target is a stream, remove the file option and also drop file modifier options like blockSize/bufferSize/replication/progressable"],"exampleFix":"// before\nWriter w = SequenceFile.createWriter(conf,\n    Writer.file(p), Writer.stream(out),\n    Writer.keyClass(Text.class), Writer.valueClass(Text.class)); // throws\n\n// after\nWriter w = SequenceFile.createWriter(conf,\n    Writer.file(p),\n    Writer.keyClass(Text.class), Writer.valueClass(Text.class));","handlingStrategy":"validation","validationCode":"// assemble options so exactly one destination is ever added\nSequenceFile.Writer.Option[] opts;\nif (out != null) {\n  opts = new Option[]{ Writer.stream(out), Writer.keyClass(kc), Writer.valueClass(vc) };\n} else {\n  opts = new Option[]{ Writer.file(path), Writer.keyClass(kc), Writer.valueClass(vc) };\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Encapsulate writer creation in one factory method so destination options are chosen in a single place","Never copy option lists between file-based and stream-based call sites"],"tags":["hadoop","sequence-file","api-misuse","invalid-argument"],"backgroundTag":"invalid-argument-combination","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}