{"record":{"id":"7eebc454c8fddbf2","repo":"apache/flink","slug":"could-not-create-csv-generator","errorCode":null,"errorMessage":"Could not create CSV generator.","messagePattern":"Could not create CSV generator\\.","errorType":"exception","errorClass":"FlinkRuntimeException","httpStatus":null,"severity":"error","filePath":"flink-formats/flink-csv/src/main/java/org/apache/flink/formats/csv/CsvBulkWriter.java","lineNumber":66,"sourceCode":"            CsvMapper mapper,\n            CsvSchema schema,\n            Converter<T, R, C> converter,\n            @Nullable C converterContext,\n            FSDataOutputStream stream) {\n        checkNotNull(mapper);\n        checkNotNull(schema);\n\n        // Prevent Jackson's writeValue() method calls from closing the stream.\n        mapper.getFactory().disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);\n        mapper.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE);\n\n        this.converter = checkNotNull(converter);\n        this.stream = checkNotNull(stream);\n        this.converterContext = converterContext;\n        try {\n            this.generator = mapper.writer(schema).createGenerator(stream, JsonEncoding.UTF8);\n        } catch (IOException e) {\n            throw new FlinkRuntimeException(\"Could not create CSV generator.\", e);\n        }\n    }\n\n    /**\n     * Builds a writer with Jackson schema and a type converter.\n     *\n     * @param mapper The specialized mapper for producing CSV.\n     * @param schema The schema that defined the mapping properties.\n     * @param converter The type converter that converts incoming elements of type {@code <T>} into\n     *     elements of type JsonNode.\n     * @param stream The output stream.\n     * @param <T> The type of the elements accepted by this writer.\n     * @param <C> The type of the converter context.\n     * @param <R> The type of the elements produced by this writer.\n     */\n    static <T, R, C> CsvBulkWriter<T, R, C> forSchema(\n            CsvMapper mapper,\n            CsvSchema schema,","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-csv/src/main/java/org/apache/flink/formats/csv/CsvBulkWriter.java#L48-L84","documentation":"Thrown by the CsvBulkWriter constructor when Jackson's CsvMapper fails to create a JsonGenerator over the output stream (mapper.writer(schema).createGenerator(stream, UTF8)). It is a setup-time FlinkRuntimeException: the writer could not be built, so no bulk write can proceed. Almost always the cause is an I/O problem on the target stream (closed/null-underlying FS stream, permissions) rather than CSV-specific logic.","triggerScenarios":"Constructing CsvBulkWriter via CsvBulkWriter.forSchema/forFailureHandler on an output stream that is already closed or whose underlying filesystem endpoint failed at open; interceptors wrapping streams that throw on first write-header; charset/encoding issues on exotic platforms.","commonSituations":"Filesystem connector sinks where the stream handed to BulkWriter.Factory points at an unreachable object store (S3/OSS credentials expired between stream creation and writer creation); test harnesses passing mocked streams that reject writes.","solutions":["Check the attached cause (IOException) — it names the real stream/FS failure.","Verify the output location is writable and the filesystem credential/endpoint still valid (e.g. s3a connection test).","If the stream is created elsewhere, ensure it is open and not already consumed/closed before CsvBulkWriter construction.","Retry the job from checkpoint after fixing the FS issue; this is a transient/environmental failure, not a data error."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Validate the stream is usable before constructing the writer:\nif (stream == null) throw new IllegalStateException(\"output stream is null\");\ntry { stream.flush(); } catch (IOException e) { /* fail before writer construction with a clear message */ }","typeGuard":null,"tryCatchPattern":"catch (FlinkRuntimeException e) { if (e.getCause() instanceof IOException) { /* transient FS failure: restart from last checkpoint after verifying object-store access */ } throw e; }","preventionTips":["Check filesystem connectivity/credentials before job submission","Enable checkpoints so bulk-writer setup retries cleanly","Don't pre-close or wrap streams passed to BulkWriter.Factory"],"tags":["csv","jackson","bulk-writer","filesystem","io"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}