{"record":{"id":"ecf1d94a8c07fd11","repo":"apache/seatunnel","slug":"event-must-not-be-empty-ecf1d9","errorCode":null,"errorMessage":"event must not be empty","messagePattern":"event must not be empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"seatunnel-edge-agent/seatunnel-edge-agent-connector/src/main/java/org/apache/seatunnel/edge/agent/connector/file/output/LineOutputFormatter.java","lineNumber":37,"sourceCode":"\nimport org.apache.seatunnel.shade.com.fasterxml.jackson.core.JsonProcessingException;\nimport org.apache.seatunnel.shade.com.fasterxml.jackson.databind.ObjectMapper;\nimport org.apache.seatunnel.shade.com.fasterxml.jackson.databind.node.ArrayNode;\nimport org.apache.seatunnel.shade.com.fasterxml.jackson.databind.node.ObjectNode;\n\nimport org.apache.seatunnel.edge.agent.connector.file.multiline.MultilineAssembler;\nimport org.apache.seatunnel.edge.agent.connector.record.CollectedRecord;\n\nimport java.util.List;\n\npublic class LineOutputFormatter implements OutputFormatter {\n\n    private final ObjectMapper objectMapper = new ObjectMapper();\n\n    @Override\n    public CollectedRecord format(List<MultilineAssembler.LineElement> event, String sourceId) {\n        if (event.isEmpty()) {\n            throw new IllegalArgumentException(\"event must not be empty\");\n        }\n        MultilineAssembler.LineElement first = event.get(0);\n        MultilineAssembler.LineElement last = event.get(event.size() - 1);\n        try {\n            String json;\n            if (event.size() == 1) {\n                ObjectNode node = buildLineObject(0, first, first.getText());\n                json = objectMapper.writeValueAsString(node);\n            } else {\n                ArrayNode array = objectMapper.createArrayNode();\n                for (int i = 0; i < event.size(); i++) {\n                    MultilineAssembler.LineElement e = event.get(i);\n                    array.add(buildLineObject(i, e, e.getText()));\n                }\n                json = objectMapper.writeValueAsString(array);\n            }\n            return new CollectedRecord(\n                    json,","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-edge-agent/seatunnel-edge-agent-connector/src/main/java/org/apache/seatunnel/edge/agent/connector/file/output/LineOutputFormatter.java#L19-L55","documentation":"LineOutputFormatter.format() requires a non-empty list of LineElement because it reads the first and last elements to build the CollectedRecord boundaries. An empty event has no valid line range, so it is rejected with IllegalArgumentException.","triggerScenarios":"Calling format() with an empty list, usually from an upstream MultilineAssembler flushing an empty buffer.","commonSituations":"Flush on empty buffer at file rotation or shutdown; a filter step that removed all lines; passing the result of an empty read straight to the formatter.","solutions":["Check event.isEmpty() before invoking the formatter and skip the call","Fix the assembler so flush() is a no-op when the buffer is empty","Wrap the call in try-catch for IllegalArgumentException as a defensive last resort"],"exampleFix":"// before\nCollectedRecord r = lineFormatter.format(event, sourceId);\n// after\nif (event == null || event.isEmpty()) {\n    return;\n}\nCollectedRecord r = lineFormatter.format(event, sourceId);","handlingStrategy":"type-guard","validationCode":"if (event == null || event.isEmpty()) { return; }","typeGuard":"boolean hasEvent(List<MultilineAssembler.LineElement> e) { return e != null && !e.isEmpty(); }","tryCatchPattern":"try { lineFormatter.format(event, sourceId); } catch (IllegalArgumentException e) { LOG.warn(\"Ignoring empty event\", e); }","preventionTips":["Guard against empty lists before any formatter call","Make assembler flush idempotent on empty buffers","Unit-test the flush path for empty-buffer behavior"],"tags":["java","empty-collection","precondition"],"backgroundTag":"empty-required-field","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}